chart-tool
chart-tool copied to clipboard
Tweak ChartTool.update()
I want to invoke ChartTool.update()
to refresh a chart on a page. According to the front-end API docs, you need to do update(id, obj)
.
A few issues:
- It's not clear from the docs what sort of object
obj
is meant to be. - Apparently
update()
wants anid
value WITHOUT the "ct-" prefix ... BUT,ChartTool.read()
requires the "ct-" prefix. The API should be standardized so both use the same ID format. Here's an example of how I'm working around that right now:
const this_chart = querySelector('.ct-chart');
let this_id = this_chart.getAttribute('data-chartid');
const obj = ChartTool.read(this_id);
this_id = this_id.replace('ct-','');
ChartTool.update(this_id,obj.data);
- It might be worthwhile to change
update()
so that theobj
parameter is optional. If it's omitted, then ChartTool just redraws the existing chart that matches the ID using the internal data it already has. Ifobj
is provided, then CT updates the chart with the new values.