Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: How to define colors in a pieChart from CDE

  1. #1

    Default How to define colors in a pieChart from CDE

    Hello,
    it might be a basic question but I can't figure it out in CDE.
    I have piechart with following values:

    "Yes": 9
    "No": 34
    "Unknown": 23
    "No Data": 4

    I want the slice that corresponds to "No" to be always red, "Yes" always green etc.

    I believe I cannot use the "colors" property because sometimes some of those categories might be missing so it messes up the order.
    If I use the extension point pie_fillStyle, it can only be a function(d) {} where d is a value not a category that corresponds to that value.

    I am sure I'm missing something basic here.
    Thanks for any suggestions
    Last edited by elkarel; 07-18-2012 at 12:11 PM.

  2. #2
    Join Date
    Nov 2005
    Posts
    164

    Default

    I used the postExecution function to do this. You need to get a handle on the visible categories:

    function f(){
    var wedge = this.chart.pieChartPanel.pvPie;
    var categories = this.chart.dataEngine.getVisibleCategories();
    var ColorMap = [["Yes", "red"], ["No", "green"], ["Unknown", "orange"], ["No Data", "blue"]];

    wedge.fillStyle(function() {
    if(categories[this.index] == ColorMap[0][0]) {
    return ColorMap[0][1];
    }
    else if(categories[this.index] == ColorMap[1][0]) {
    return ColorMap[1][1];
    }
    else if(categories[this.index] == ColorMap[2][0]) {
    return ColorMap[2][1];
    }
    else {
    return ColorMap[3][1];
    }
    });
    wedge.root.render();

    }

    Of course, this works well until you have many categories because of the nested if / else statements, but if you only have a few, it does the job.

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.