chart-tool icon indicating copy to clipboard operation
chart-tool copied to clipboard

Tweak ChartTool.update()

Open Kirkman opened this issue 3 years ago • 0 comments

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:

  1. It's not clear from the docs what sort of object obj is meant to be.
  2. Apparently update() wants an id 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);
  1. It might be worthwhile to change update() so that the obj 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. If obj is provided, then CT updates the chart with the new values.

Kirkman avatar May 25 '21 18:05 Kirkman