Chartjs-How to add an array to my line data?

1πŸ‘

βœ…

is it that you just want to use the arrays you declare in the setup of your data? If so you can just reference them directly

var data = {
    labels: ArrayForTheDate,

    datasets: [{
            label: "Usage Plan",
            fillColor: "rgba(0,0,0,0.2)", //adds the color below the line
            strokeColor: "rgba(224,0,0,1)", //creates the line
            pointColor: "rgba(244,0,0,1)", //gets rid of the circle
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(220,220,220,1)",
            data: ArrayForHoldingTheUsageInformation
        }, {
            label: "Overall Usage",
            fillColor: "rgba(48,197,83,0.2)",
            strokeColor: "rgba(48,197,83,1)",
            pointColor: "rgba(48,197,83,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(48,197,83,1)",
            data: ArrayForTotalUsage
        }, {
            label: "Daily Usage",
            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: ArrayForDailyUsage
        }
    ]
};

here is a fiddle usign some data to show it working http://jsfiddle.net/leighking2/35o54t2L/

Leave a comment