0

I'm dynamically creating chart objects using this code inside a loop:

chartObjectArray.push(new Chart(chartContextArray[i]).Line(chartDataArray[i]), chartOptions);

The charts get drawn on the screen, but the chartOptions parameter is essentially ignored. However, if I manually create the chart objects like this...

var myChart = new Chart(chartContextArray[0]).Line(data, chartOptions);

...then it works; options are obeyed when charts are drawn. This chart object (myChart) when logged is much more fully fleshed-out than the object created from the loop. Am I incorrectly building the chart objects in the loop? Perhaps this is more of a javascript question.

Grid Trekkor
  • 1,443
  • 2
  • 14
  • 19
  • are you able to post your full code to see what is happening? Or even better in a fiddle to reproduce the error – Quince Nov 14 '15 at 22:02

1 Answers1

0

If you have different chart options for each chart, you need to create a clone of the chartOptions object for each chart.

For plain JavaScript, I usually prefer https://stackoverflow.com/a/4591639/360067 for its simplicity, but if you have libraries (jQuery, etc) you have a lot of other options.

Community
  • 1
  • 1
potatopeelings
  • 40,709
  • 7
  • 95
  • 119