Hitachi Vantara Pentaho Community Forums
Results 1 to 8 of 8

Thread: Chart providing the same color for a given category!!!

  1. #1

    Default Chart providing the same color for a given category!!!

    Hi all,
    the problem is that I have a CCC Pie Chart with some categories, the datasource depends on a parameter so the colors are not linked to a specific Category and they change.

    I searched for a solution and I faced this by the user "duarte.leao":

    "...
    You might need to have an external "category to color" map that would provide the same color for a given category, on any of the charts.
    You can't depend on the category index for this, as a given category, in each chart, may come in a different resultset position, and not come in one but come in another.
    So, an external shared color scale would do it. If you don't specify the domain explicitly the existing colors are assigned to requested categories, in the order they are asked for.

    var sharedColorScale = pv.colors(['red', 'blue', 'green']);
    sharedColorScale('Categ A'); // -> red
    sharedColorScale('Categ B'); // -> blue
    sharedColorScale('Categ A'); // -> red (remenbered)
    sharedColorScale('Categ C'); // -> green
    sharedColorScale('Categ D'); // -> red again
    sharedColorScale('Categ E'); // -> blue again
    ...

    Then, you would have to dynamically change the colors of bars and pie slices and legends using extension points that read the value of the category and return a corresponding color.
    Notice that each scale you create memorizes the created correspondences between categories and colors, so you should create a new shared color scale instance whenever you want to clear that memory.
    Hope this helps."

    Can someone help me about where to write the above code

    Thank you all

  2. #2
    Join Date
    Mar 2012
    Posts
    645

    Default

    The post you referred to applied to CCCv1.

    Although the technique would work in CCCv2 as well, there's a new and easier way to do it.

    Specify the following option in the chart's CDE component "postFetch" handler:

    Code:
    function f() {
        // Series Value => Fixed Color
        this.chartDefinition.colorMap = {
            "Madrid": 'green',
            "Lisbon": 'red'
        };
    }
    Other needed colors are taken from the normal "colors" property.

    At the time of writing, the property is not documented nor is it available as a CDE UI property.

  3. #3

    Default

    Thanks for your reply. I edited the PostFetch like this:

    function f() {
    // Series Value => Fixed Color
    this.chartDefinition.colorMap = {
    "OK": 'green',
    "KO": 'red',
    "Warning": 'yellow'
    };
    }

    but nothing happened. Do I miss something?
    Sorry, I am a very newbie to javascript and web developer

  4. #4
    Join Date
    Mar 2012
    Posts
    645

    Default

    Please check that you're using CCCv2 and that it is a recent CCCv2 version.

    You can check the CCC version in the folder ...biserver-ee/pentaho-solutions/system/pentaho-cdf/js/lib/CCC.
    You should have a file named pvc-d2.0.js. Open it and check the timestamp in the first line.

    If you can, just update CDF, CGG and CDE to the latest trunk/dev version.

  5. #5

    Default

    Thank you man! Now it works!!!
    Last edited by andrea.botto; 03-08-2013 at 10:52 AM.

  6. #6
    Join Date
    Aug 2014
    Posts
    10

    Default

    Hello,

    can you help me on apply colur for multple charts.

    i have created 4 charts 2 bar charts and 2 multiple pie charts.when i click first bar chart i need to apply same value for all charts

    ex : Name:  img.jpg
Views: 280
Size:  10.0 KB

    exaplme image. same second bar chart chart also i have to apply. using pie chart as a multple pie charts

  7. #7
    Join Date
    Aug 2014
    Posts
    10

    Default

    Hello,

    can you help me on apply colur for multple charts.

    i have created 4 charts 2 bar charts and 2 multiple pie charts.when i click first bar chart i need to apply same value for all charts

    ex :

    exaplme image. same second bar chart chart also i have to apply. using pie chart as a multple pie charts

  8. #8
    Join Date
    Mar 2012
    Posts
    645

    Default

    Hello,

    so if I understood correctly, you want that when a bar is selected, the corresponding slices in the other chart are selected as well?
    But this would have nothing to do with colors and this forum thread. Did I get it wrong? If it is the case, please create a new thread :-)
    (EDIT - new thread: http://forums.pentaho.com/showthread...-on-data-value)
    Last edited by duarte.leao; 08-07-2014 at 08:31 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.