Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: How to toggle visibility of a legend item on a chart, when chart is first loaded?

  1. #1

    Default How to toggle visibility of a legend item on a chart, when chart is first loaded?

    When a barline chart is loaded, I would like a series type in the legend to be 'unselected' when the chart initially loads.
    I am using CCCv2.
    I see the methods toggleSelected and setSelected, but cannot find any relevant methods to 'turn off' a line within my barline chart upon initial load.

    Please let me know how this can be done.

    Thank you

  2. #2
    Join Date
    Mar 2012
    Posts
    645

    Default

    For reference to other users, you're probably referring to the "initially selected" method explained here.

    A good thing of abstraction is that it reveals higher level operations and makes them easier and more concise to write.
    A bad thing, is that it also hides simple things.

    The code of the referenced example could also be written as:
    Code:
    renderCallback: function(){
        // Obtain datums to be selected.    
        // * all datums whose 'series' dimension has value 'London' and "category" dimension is "2013-02-24"
        var datums = this.chart.data.datums([{series: 'London', category: "2012-02-24"}]);
    
        // Select them all:
        datums.each(function(datum) {
            datum.setSelected(true);
        });
    }
    While it looks like what you are currently asking for could thus be achieved like:
    Code:
    renderCallback: function() {
        var datums = this.chart.data.datums([{series: 'London', category: "2012-02-24"}]);
    
        // Hide them all:
        datums.each(function(datum) {
            datum.setVisible(false);
        });
    }
    in reality, the renderCallback is not the right place to set the initial datum's visibility - it occurs too late.
    We would need an "dataLoadedCalback" or something...

    So the only way I can think of for achieving this *now*, is to re-render the chart, immediately after the the first render.
    In the postExecution handler do something like:
    Code:
    function f() {
         var datums = this.chart.data.datums([{series: 'London', category: "2012-02-24"}]);
            
         // Hide them all:
         datums.each(function(datum) {
             datum.setVisible(false);
         });
    
         // Re-render the chart
         this.chart.render(/*bypassAnimation*/true, /*recreate*/true, /*reloadData*/false);
    }

    In the mean-time we'll consider the addition of a handler like "
    dataLoadedCalback" to serve these purposes.
    Last edited by duarte.leao; 04-20-2015 at 08:34 AM. Reason: removed the _inited flag from the last example

  3. #3
    Join Date
    Oct 2014
    Posts
    8

    Default

    hello, everybody Great God,
    I have a problem.
    I am referring to duarte.leao code, but did not hide.
    After my test found
    Icon initialization: this.isvisible = true
    In the Post Execution hidden code execution time: this.isvisible = false
    But the icon and then changed back loading is complete: this.isvisible = true

    But when I click on the series, when performed inside the hidden code Post Execution: this.isvisible = false

    I hope to be able to load after the completion of an icon: this.isvisible = false to hide the line
    function f(){
    if(!this._inited_) {
    this._inited_ = true;
    var datums = this.chart.data.datums([{series: 'ebay_uk'},{series: 'ebay_us'}]);
    datums.each(function(datum) {
    datum.setVisible(false);
    });
    this.chart.render(true, true, false);
    }
    }

  4. #4
    Join Date
    Mar 2012
    Posts
    645

    Default

    Hi annisum,

    I couldn't understand what you wrote.
    I did look at the example below and removed the "_inited" flag, which is also in your code.
    In many cases, this flag doesn't make sense, as you should set the datum visibility in every execution.

    What do you mean by Icon?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.