Home forums Using CanvasJS Changing options after creating the chart.

This topic contains 12 replies, has 2 voices, and was last updated by  Sunil Urs 2 years, 9 months ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #5922

    Daniel Silva
    Participant

    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

    #5924

    Daniel Silva
    Participant

    Its chart.options.theme=”theme2″;
    Still doesn’t work :/

    #5925

    Sunil Urs
    Keymaster

    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

    #5926

    Daniel Silva
    Participant

    If we could change any of the options and them call render would be great 🙂

    Thanks

    #5930

    Sunil Urs
    Keymaster

    Daniel,

    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.


    Sunil Urs

    #5934

    Daniel Silva
    Participant

    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);

    Br,
    Daniel

    #5949

    Daniel Silva
    Participant

    Is possible to change the options object by another or I have to change the attributes one by one?
    Thanks

    #5959

    Sunil Urs
    Keymaster

    Daniel,

    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.


    Sunil Urs

    #5960

    Daniel Silva
    Participant

    Hi,

    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.

    Thanks

    #5976

    Sunil Urs
    Keymaster

    Daniel,

    We have decided to implement this feature. Am already half way through. You can expect this feature in a day or two.


    Sunil Urs

    #5977

    Sunil Urs
    Keymaster

    Daniel,

    Here is an intermediate build with the above mentioned feature. Please have a look and let me know if its working as expected.


    Sunil Urs

    #5997

    Daniel Silva
    Participant

    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.

    Br,
    Daniel

    #6000

    Sunil Urs
    Keymaster

    Thats great.. Thanks for choosing us… 🙂

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.