Advertisement
Guest User

canvasjs line chart

a guest
Mar 19th, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE HTML>
  2. <html>
  3.  
  4. <head>  
  5. <script type="text/javascript" src = "http://canvasjs.com/wp-content/themes/bootstrap_child/assets/js/jquery-1.8.3.min.js"> </script>
  6. <script type="text/javascript" src="http://canvasjs.com/assets/script/canvasjs.min.js"></script>
  7.  
  8. </head>
  9. <body>
  10. <div id="chartContainer" class="chart">
  11. <script type="text/javascript">
  12.  
  13.  data=[
  14. {
  15.     "Date": "2014-01-30",
  16.     "CarsParked": "1",
  17.     "RevenueWithTip": "0",
  18.     "Revenue": "0",
  19.     "Tip": "0",
  20. },
  21. {
  22.     "Date": "2014-01-31",
  23.     "CarsParked": "10",
  24.     "RevenueWithTip": "10",
  25.     "Revenue": "7",
  26.     "Tip": "3",
  27. },
  28. {
  29.     "Date": "2014-02-28",
  30.     "CarsParked": "28",
  31.     "RevenueWithTip": "55",
  32.     "Revenue": "47",
  33.     "Tip": "8",
  34. }];
  35.  
  36.     var len = data.length;
  37.  
  38.     $.each(data, function(i, v) {              
  39.         chart(v.Date,v.Tip,v.Revenue,len);
  40.     });
  41.  
  42.  
  43.  
  44.   function chart (dates,Tip,Rev,len) {
  45.  
  46.     var chart = new CanvasJS.Chart("chartContainer", {
  47.         title: {
  48.             text: "Revenue",
  49.             fontSize: 15
  50.         },
  51.         axisX: {
  52.             gridColor: "Silver",
  53.             tickColor: "silver",
  54.             valueFormatString: "DD/MMM"
  55.         },                        
  56.         toolTip: {
  57.             shared:true
  58.         },
  59.         theme: "theme2",
  60.         axisY: {
  61.             gridColor: "Silver",
  62.             tickColor: "silver"
  63.         },
  64.         legend: {
  65.             verticalAlign: "center",
  66.             horizontalAlign: "right"
  67.         },
  68.         data: [
  69.             {                  
  70.                 type: "line",
  71.                 showInLegend: true,
  72.                 lineThickness: 2,
  73.                 name: "Tip",
  74.                 markerType: "square",
  75.                 color: "#F08080",
  76.                 dataPoints: [
  77.                     {
  78.                         x: new Date(dates),
  79.                         y: parseInt(Tip)
  80.                     }
  81.                 ]
  82.             },
  83.             {        
  84.                 type: "line",
  85.                 showInLegend: true,
  86.                 name: "Revenue",
  87.                 color: "#20B2AA",
  88.                 lineThickness: 2,
  89.                 dataPoints: [
  90.                     {
  91.                         x: new Date(dates),
  92.                         y: parseInt(Rev)
  93.                     }
  94.                 ]
  95.             }
  96.         ],
  97.         legend: {
  98.             cursor: "pointer",
  99.             itemclick: function(e) {
  100.                 if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
  101.                     e.dataSeries.visible = false;
  102.                 } else {
  103.                     e.dataSeries.visible = true;
  104.                 }
  105.                 chart.render();
  106.             }
  107.         }
  108.     });
  109.  
  110.     chart.render();
  111.  
  112.  
  113. }
  114. </script>
  115. </body>
  116.  
  117. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement