1
votes

I am using Chart.js for plotting a simple line chart.

I have the following line chart data which works fine. Three data values are mapped to three labels.

var lineChartData = {
    labels : ["January","February","March"],
    datasets : [
        {
            fillColor : "rgba(151,187,205,0.5)",
            strokeColor : "rgba(151,187,205,1)",
            pointColor : "rgba(151,187,205,1)",
            pointStrokeColor : "#fff",
            data : [10, 5, 7]
        }
    ]
}

Now I want to add a set of data values to one label, e.g. 30 different values, one for each day of a month. I already tried something like

data : [{10, 5, 7, ..., 3}, {5, 6, 8, ..., 4}, ...]

But without success.

How can I map a data set of values to a single label in Chart.js?

1

1 Answers

0
votes

Make them seperate objects.

var lineChartData = {
    labels : ["January","February","March"],
    datasets : [
        {
            fillColor : "rgba(151,187,205,0.5)",
            strokeColor : "rgba(151,187,205,1)",
            pointColor : "rgba(151,187,205,1)",
            pointStrokeColor : "#fff",
            data : [10, 5, 7]
        },

{
            fillColor : "rgba(151,187,205,0.5)",
            strokeColor : "rgba(151,187,205,1)",
            pointColor : "rgba(151,187,205,1)",
            pointStrokeColor : "#fff",
            data : [3, 9, 4]
        }
    ]
}