Want to set palette of a pie chart

Posted by: ed on 5 March 2019, 8:05 pm EST

    • Post Options:
    • Link

    Posted 5 March 2019, 8:05 pm EST

    I am trying to set the palette of my pie chart to “cocoa” using this code

    theChart.palette = wijmo.chart.Palettes[cocoa];

    I was following an example at https://demos.wijmo.com/5/PureJS/LearnWijmo/LearnWijmo/#aszrs9ho

    When I run the application I get an error in the console saying

    Invoices:174 Uncaught ReferenceError: cocoa is not defined

    at onload

    Is ‘cocoa’ still a valid palette choice or do I have to create a custom palette?

    Also, I have this code to add the chart;

    var chart = new wijmo.chart.FlexPie(‘#theChart’, {

    isAnimated: true,

    selectionMode: wijmo.chart.SelectionMode.Point,

    selectedItemPosition: wijmo.chart.Position.Auto,

    selectedItemOffset: 0.3,

    innerRadius: 0.5,

    });

    How can I set the palette color here?

    Thanks, Ed

  • Posted 6 March 2019, 12:43 am EST

    Hi Ed,

    It seems like, there is a typo in the code which is causing the issue. We need ‘cocoa’ as string whereas in the snippet you shared it is passed as a variable(forgetting the quote marks).

    Please refer to the following code snippet:

    theChart.palette = wijmo.chart.Palettes[[b]'cocoa'[/b]];
    

    We could set the palette at the time of initialization easily by setting the palette property in the initialization options just like any other property. Please refer to the following code snippet:

    var chart = new wijmo.chart.FlexPie('#theChart', {
    isAnimated: true,
    selectionMode: wijmo.chart.SelectionMode.Point,
    selectedItemPosition: wijmo.chart.Position.Auto,
    selectedItemOffset: 0.3,
    innerRadius: 0.5,
    [b]palette: wijmo.chart.Palettes['cocoa'][/b]
    });
    

    You may also refer to the following sample demonstrating the same: https://jsfiddle.net/d8u52zct/1/

    ~Sharad

  • Posted 6 March 2019, 12:43 pm EST

    Thank you very much.

    Ed

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels