two line in line chart - Javascript Chart.js

Javascript examples for Chart.js:Line Chart

Description

two line in line chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://rawgit.com/nnnick/Chart.js/v1.0.2/Chart.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//ww  w . j av a 2  s.c o  m
Chart.types.Line.extend({
    name: "LineAlt",
    initialize: function (data) {
        Chart.types.Line.prototype.initialize.apply(this, arguments);
        if (this.options.every) {
            var every = this.options.every;
            var xLabels = this.scale.xLabels
            xLabels.forEach(function (label, i) {
                if (i % every !== 0)
                    xLabels[i] = '';
            })
        }
    }
});
var data = {
    labels: ["07-30", "07-30", "07-31", "07-31", "07-31", "07-31", "08-03", "08-04", "08-05", "08-05", "08-05", "08-06", "08-06", "08-07", "08-07", "08-07", "08-07", "08-08"],
    datasets: [
        {
            label: "My First dataset",
            fillColor: "rgba(220,220,220,0.2)",
            strokeColor: "rgba(220,220,220,1)",
            pointColor: "rgba(220,220,220,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(220,220,220,1)",
            data: [65, 59, 80, 81, 56, 55, 40, 59, 80, 81, 56, 55, 40, 12, 43, 23, 43, 12]
        },
        {
            label: "My Second dataset",
            fillColor: "rgba(151,187,205,0.2)",
            strokeColor: "rgba(151,187,205,1)",
            pointColor: "rgba(151,187,205,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(151,187,205,1)",
            data: [43, 23, 43, 12, 65, 59, 80, 81, 56, 55, 40, 59, 80, 81, 56, 55, 40, 12]
        }
    ]
};
var ctx = document.getElementById("chart").getContext("2d");
var myLineChart = new Chart(ctx).LineAlt(data, {
    every: 3
});
    }

      </script> 
   </head> 
   <body> 
      <canvas id="chart" height="300" width="500"></canvas>  
   </body>
</html>

Related Tutorials