我如何将值从C#传递到客户端jQuery [英] How I pass value from c# to client side jquery

查看:136
本文介绍了我如何将值从C#传递到客户端jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想使用Jquery在asp.net中创建图表,但数据来自服务器端c#和Sql Server


HTML代码

Hi


I want to create a charts in asp.net using Jquery but the data comes from server side c# and Sql Server


Html Code

<!DOCTYPE HTML>
<html>

<head>
  <script type="text/javascript">
  window.onload = function () {
    var chart = new CanvasJS.Chart("chartContainer",
    {
      theme: "theme2",
      title:{
        text: "Earthquakes - per month"
      },
      animationEnabled: true,
      axisX: {
        valueFormatString: "MMM",
        interval:1,
        intervalType: "month"

      },
      axisY:{
        includeZero: false

      },
      data: [
      {
        type: "line",
        //lineThickness: 3,
        dataPoints: [
        { x: new Date(2012, 00, 1), y: 450 },
        { x: new Date(2012, 01, 1), y: 414},
        { x: new Date(2012, 02, 1), y: 520, indexLabel: "highest",markerColor: "red", markerType: "triangle"},
        { x: new Date(2012, 03, 1), y: 460 },
        { x: new Date(2012, 04, 1), y: 450 },
        { x: new Date(2012, 05, 1), y: 500 },
        { x: new Date(2012, 06, 1), y: 480 },
        { x: new Date(2012, 07, 1), y: 480 },
        { x: new Date(2012, 08, 1), y: 410 , indexLabel: "lowest",markerColor: "DarkSlateGrey", markerType: "cross"},
        { x: new Date(2012, 09, 1), y: 500 },
        { x: new Date(2012, 10, 1), y: 480 },
        { x: new Date(2012, 11, 1), y: 510 }

        ]
      }


      ]
    });

chart.render();
}
</script>
<script type="text/javascript" src="/assets/script/canvasjs.min.js"></script></head>
<body>
  <div id="chartContainer" style="height: 300px; width: 100%;">
  </div>
</body>

</html>




现在,我想从数据库传递x轴和Y轴值.请帮助我




Now I want to pass x-axis and Y-axis value from database . Please Help me

推荐答案

,当您的视图加载从数据库中获取x和y轴值并将其放在Viewbag元素中.然后,您可以在jquery中轻松访问Viewbag
when your view loads get the x and y axis value from database and put that inside a Viewbag element.Then Viewbag you can easily access in jquery


这篇关于我如何将值从C#传递到客户端jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆