You must be logged in to post your query.
Home › Forums › Chart Support › Changing options after creating the chart.
Hi,
I’m trying to change some of the chart options after creating the object.
The title works great: chart.options.title.text=”another title”;
But theme doesn’t: chart.options=”theme2″;
http://jsfiddle.net/dreamfalcon/ravXa/
Is this possible? I want to create a form where the user could change some of the charts options.
Br, Daniel
Its chart.options.theme=”theme2″; Still doesn’t work :/
Daniel,
I can confirm the issue. Am currently working towards fixing the same. Will get back at the earliest with a new build – probably in a day or two.
— Sunil Urs
If we could change any of the options and them call render would be great :)
Thanks
Here is an intermediate build with the fix – allows updating all attributes. Please have a look and let me know if its working as expected.
Hi, In the example I give is working great. Then I tried to send all options by json to PHP, alter the theme, return also by json, change the chart options,render the chart, and the theme is not altered.
JS:
var chart = new CanvasJS.Chart("content", { theme: "theme1", title:{ text: "Changing Theme" }, data: [ { type: "column", dataPoints: [ { x: 10, y: 71 }, { x: 20, y: 55}, { x: 30, y: 50 }, { x: 40, y: 65 }, { x: 50, y: 95 }, { x: 60, y: 68 }, { x: 70, y: 28 }, { x: 80, y: 34 }, { x: 90, y: 14} ] } ] }); chart.render(); var json=JSON.stringify(chart); success = function(jsonObject) { chart.options=JSON.parse(jsonObject.chartOptions); chart.render(); }; jsonRequest(json,success);
PHP:
$s=json_decode ( $_REQUEST['json'] ,true); $s['options']['theme']="theme2"; $response->chartOptions=json_encode ($s);
Is possible to change the options object by another or I have to change the attributes one by one? Thanks
By design it is not allowed to set the options object itself but you can change its attributes. But we’ll reconsider this for upcoming versions.
An alternative for what I need is saving the original object used to create the chart, modify this object, destroy the old chart and creating a new chart with the new object. But that will increase memory in case of dashboards with many charts.
We have decided to implement this feature. Am already half way through. You can expect this feature in a day or two.
Here is an intermediate build with the above mentioned feature. Please have a look and let me know if its working as expected.
It’s working great, many thanks. Unfortunately I had to stop the development of the reports because of another project, but I expect to buy and migrate all charts to CanvasJS in a few weeks.
Thats great.. Thanks for choosing us… :-)
You must be logged in to reply to this topic. Login/Register