сохранить объект для всех инициализированных диаграмм, используя датчик js - PullRequest
0 голосов
/ 21 апреля 2019

У меня есть вопрос, связанный не только с датчиком js, как именно хранить объект инициализированных элементов на html-странице, но и с датчиком js. У меня есть следующее

<canvas id="pieChart1"></canvas>
<canvas id="pieChart2"></canvas>
<canvas id="pieChart3"></canvas>
...

и в JS я запускаю диаграмму для всех холстов

function initChart(canvasID){
var opts = {
  angle: 0.15, // The span of the gauge arc
  lineWidth: 0.44, // The line thickness
  radiusScale: 1, // Relative radius
  pointer: {
    length: 0.6, // // Relative to gauge radius
    strokeWidth: 0.035, // The thickness
    color: '#000000' // Fill color
  },
  limitMax: false,     // If false, max value increases automatically if value > maxValue
  limitMin: false,     // If true, the min value of the gauge will be fixed
  colorStart: '#6FADCF',   // Colors
  colorStop: '#8FC0DA',    // just experiment with them
  strokeColor: '#E0E0E0',  // to see which ones work best for you
  generateGradient: true,
  highDpiSupport: true,     // High resolution support

};
var target = document.getElementById('foo'); // your canvas element
var gauge = new Gauge(target).setOptions(opts); // create sexy gauge!
gauge.maxValue = 3000; // set max gauge value
gauge.setMinValue(0);  // Prefer setter over gauge.minValue = 0
gauge.animationSpeed = 32; // set animation speed (32 is default value)
gauge.set(1250); // set actual value
}

initChart('#pieChart1');
initChart('#pieChart2');
initChart('#pieChart3');

Как я могу обновить данные каждого графика? gauge объект не повторяется для всех графиков

...