Chartjs-tsgauge icon indicating copy to clipboard operation
Chartjs-tsgauge copied to clipboard

How to update Gauge value?

Open JosueMarinho opened this issue 5 years ago • 13 comments

gGauge.data.datasets[0].data = 10 doesn't work... Can you help me? Tanks!

JosueMarinho avatar Mar 15 '19 16:03 JosueMarinho

What did you mean? Can you show full chart config? Dataset has only such parameters: gaugeData gaugeLimits backgroundColor

kluverua avatar Mar 15 '19 17:03 kluverua

I want to change de gaugeData.

JosueMarinho avatar Mar 15 '19 17:03 JosueMarinho

myChartInstance.config.data.datasets[0].gaugeData.value = 800; myChartInstance.update({duration:0,lazy: true})

kluverua avatar Mar 15 '19 18:03 kluverua

Thank you!

JosueMarinho avatar Mar 15 '19 18:03 JosueMarinho

Is it possible to update the position of the pointer without it resetting from 0?

JosueMarinho avatar Mar 15 '19 18:03 JosueMarinho

comment this: //gaugeHelper.animateArrow(); and replace this: //gaugeHelper.renderSmallValueArrow(gaugeHelper.minValue); --> gaugeHelper.renderValueArrow();

kluverua avatar Mar 15 '19 19:03 kluverua

Perfect! ahn... and the animation? it is possible to keep?

JosueMarinho avatar Mar 15 '19 19:03 JosueMarinho

I think so, if you write some code :D

kluverua avatar Mar 15 '19 19:03 kluverua

Hello ! I tried to update the Gauge chart. I was able to update the gaugeData, but not the gaugeLimits. They just stay the same displayed, eventhough I assigned them a new array.

chart.config.data.datasets[0].gaugeLimits = [0,1,2,3,4,5];
chart.config.data.datasets[0].gaugeData.value = 3;
chart.update();

AntoniaChimp avatar Jul 16 '19 10:07 AntoniaChimp

You cant do this in current version. If you don't want to fix source code, you can try this workaround:

chart.config.data.datasets[0].gaugeLimits[0] = 0;
chart.config.data.datasets[0].gaugeLimits[1] = 1;
...
update

kluverua avatar Sep 19 '19 13:09 kluverua

how update valueColor according to the pointer! example: function updateColorValue(chart, value){ chart.data.datasets[0].gaugeData.value = value; chart.data.datasets[0].gaugeLimits.forEach(function(element, index) { if(value >= element && value < chart.data.datasets[0].gaugeLimits[index+1]){ chart.data.datasets[0].gaugeData.valueColor = chart.data.datasets[0].backgroundColor[index]; }else if(chart.data.datasets[0].gaugeLimits.length-1 == index && value >= element){ chart.data.datasets[0].gaugeData.valueColor = chart.data.datasets[0].backgroundColor[index-1]; }else if(index == 0 && value <= element){ chart.data.datasets[0].gaugeData.valueColor = chart.data.datasets[0].backgroundColor[index]; } }); chart.update(); }

AlexsanderSouza avatar Oct 02 '19 14:10 AlexsanderSouza

You cant do this in current version. If you don't want to fix source code, you can try this workaround:

chart.config.data.datasets[0].gaugeLimits[0] = 0;
chart.config.data.datasets[0].gaugeLimits[1] = 1;
...
update

Hey, this is not working :( The values of the limit gets updated but they all overlap in the position of the first one

ipokecows avatar Dec 11 '19 14:12 ipokecows

@kluverua How to add text to gaugeLimits in addition to numbers something like '1000( approximately)'. Could you please suggest?

Mridusmita18 avatar Mar 18 '21 15:03 Mridusmita18