Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

XML
<!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>



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

1 solution

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
 
Share this answer
 
Comments
Gurpreet Arora Malhotra 24-Apr-15 6:45am    
vIEWBAG IS A PART OF MVC but i want this in asp.net
[no name] 24-Apr-15 7:05am    
Hi Gurpreet,

I thought you are using MVC.

For asp.net take your jquery code out of window.onload function and declare your own function with a input argument as object and while your page loads in page_load event call the jquery function by using like below.


ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "tmp", "myFunction(params...);", false);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900