Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Labels in Varable v.s. directly assigned.

Open Wizardre opened this issue 11 years ago • 3 comments

This works: looking at the "labels" line if I put them in with quotes here like this, it will produce a chart. I need them in quotes because if I try to use 1/1/15 it gets calculated 1 divided by 1 divided by 15.

var data = {
    labels: ['1-Jan-2015', '2-Jan-2015', '3-Jan-2015', '4-Jan-2015', '5-Jan-2015', '6-Jan-2015', '7-Jan-2015', '8-Jan-2015', '9-Jan-2015', '10-Jan-2015'],
    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: [@d2]
    } 
]
};

This does not: If I assign the labels via a string variable it does not work. (I verified that label does contain exactly the same thing in the one above. You can see that with "data" it works fine since it contains a string of floats

@{string label = "'1-Jan-2015', '2-Jan-2015', '3-Jan-2015', '4-Jan-2015', '5-Jan-2015', '6-Jan-2015', '7-Jan-2015', '8-Jan-2015', '9-Jan-2015', '10-Jan-2015'";}

var data = {
    labels: [@label],
    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: [@d2]
    } 
]
}

Any help would be Greatly Appreciated!!!

Wizardre avatar Oct 15 '15 19:10 Wizardre

@Wizardre it looks like you are creating one giant label in the 2nd snippet instead of an array of strings.

etimberg avatar Oct 17 '15 02:10 etimberg

Hi All,

What about if i use a function returns array of labels. it is also not working, any help please;

labels: ChartLabels()

the function above is actually returning an array of labels.

Regards, Ather

shaikhather avatar Oct 26 '15 07:10 shaikhather

Closing as implementation issue. labels needs to be an array of strings.

etimberg avatar Dec 26 '15 15:12 etimberg