Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: Get The series name from a barchart to colour coding

  1. #1
    Join Date
    Dec 2012
    Posts
    121

    Default Get The series name from a barchart to colour coding

    Hi all,
    i have a CCC bar chart and i want to set a color coding on it depending on group (or series) values.
    I have used the extension point and set it as:

    bar_fillStyle function(s,n,v) { if(s==1) return "green"; else return "black" ;}

    p.S: my series are four: 1,2,3,4
    However, it does not work!!!

    Any suggestions is appreciated!

    Yamas

  2. #2
    Join Date
    Mar 2012
    Posts
    645

    Default

    Hi marcolino.
    I assume you're using CCCv1.
    The problem is the incorrect extension point signature - the signature you have is that of, for example, the "clickAction".

    The real signature depends on whether the bar chart is stacked or not:

    • Stacked:
      • series index = this.parent.index
      • categ. index = this.index

    • Not-Stacked (grouped)
      • series index = this.index
      • categ. index = this.parent.index


    With these indexes, you can get the corresponding series and/or category values:
    Code:
    var chart = render_«theNameOfMyCDEChartComponent».chart;
    
    // When grouped:
    var visibleSeriesIndex = this.index;
    var visibleCategIndex = this.parent.index;
    var seriesValue = chart.dataEngine.getVisibleSeries()[visibleSeriesIndex];
    var categValue = chart.dataEngine.getVisibleSeries()[visibleCategIndex];
    So your extension point could be written as:
    Code:
    bar_fillStyle: function(){
        var s = render_«theNameOfMyCDEChartComponent».chart.dataEngine.getVisibleSeries()[this.index];
        return s == '1' ? 'green' : 'black';
    }
    By the way, in CCCv2, if you only want to fixate the color of certain series, you have a useful feature: color maps.
    An example:
    Code:
    colorMap: {
        'Lisbon': 'red',
        'London': 'blue'
    }
    Other series are given colors as usual, from the "colors" property (or from the default color scale).
    This changes both the base colors of visual elements (bars, dots, ...) as well as the corresponding legend items colors.

    If you only want to change the bar color, the code would be:
    Code:
    bar_fillStyle: function(scene){
        return scene.vars.series.value == '1' ? 'green' : 'black';
    }
    Last edited by duarte.leao; 02-28-2013 at 07:25 PM.

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.