Home forums Using CanvasJS Hide datapoints programmatically

This topic contains 4 replies, has 2 voices, and was last updated by  Vishwas R 3 months, 3 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #21909

    sonerb
    Member

    Hi,
    I want to hide data points but without click legends labels.

    For example i tried like this but not working.

    var chart = new chart = new CanvasJS.Chart(...);
    
    chart.data[0].visible = false;
    chart.data[1].visible = false;
    chart.render();

    Or hide all function:

    function HideAll() {
        for (var i = 0; i < chart.data.length; i++) {
            chart.data[i].visible = false;
        }
        chart.render();
    }

    Or show all function:

    function ShowAll() {
        for (var i = 0; i < chart.data.length; i++) {
            chart.data[i].visible = true;
        }
        chart.render();
    }
    • This topic was modified 4 months ago by  sonerb.
    #21922

    Vishwas R
    Keymaster

    @sonerb,

    You are trying to update visible property directly and not through chart-options. Updating chart options should work fine in this case. Can you kindly update your code to chart.options.data[i].visible = false; instead of chart.data[i].visible = false; and the same in ShowAll() aswell.

    If this doesn’t solve your issue, kindly create jsfiddle reproducing the issue, so that we can look in to your code, understand it better and help you out.


    Vishwas R
    Team CanvasJS

    #21966

    sonerb
    Member

    @vishwas thank you for helping. It’s work for me.

    I have an another question, maybe i should open new topic but I want to ask now.
    Can I get default data color?
    I can get, if I set color properties and render. But I can’t get like this;

    var data_color = chart.options.data[0].color;

    #21967

    sonerb
    Member

    Here is my fiddle, maybe someone want to use.

    https://jsfiddle.net/QwZuf/1888/

    #21978

    Vishwas R
    Keymaster

    @sonerb,

    Once the chart is rendered, you can get dataSeries color using get method. Please take a look at this jsfiddle.


    Vishwas R
    Team CanvasJS

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

You must be logged in to reply to this topic.