US and Worldwide: +1 (866) 660-7555
Results 1 to 9 of 9

Thread: How to Overwrite The Default Color Scheme In Charts

  1. #1
    Join Date
    Oct 2009
    Posts
    122

    Default How to Overwrite The Default Color Scheme In Charts

    Hi,

    I have few charts in dashboards, i want to overwrite the color scheme and create my own customize color scheme for the charts. Is there any way of getting this.

    Regards

  2. #2

    Default

    U can do that with the "colors" property... if u wanna do that for "all" charts u could make a function and call it at pre-execution that changes the "chartDef.options.colors" and pass an array of colors... somethigs like:

    function myColors(preChart) { /*this way... single func. with pre-def. colors array */
    preChart.chartDefinition.colors = array('red','green','blue');
    }

    pre-exec call:

    function myPre(){ myColors(this); }

    OR function myPre() { this.chartDefinition.colors = array('red','green','blue'); } /*dont make much sense... since it would be done the same with the property... */

  3. #3
    Join Date
    Mar 2012
    Posts
    129

    Default

    Just commited a feature in the DEV branch of CDF and CGG that allows you to do just that (it was already developed, by CvK, and was pending to be integrated into CDF and CGG).

    The change in CDF:
    https://github.com/webdetails/cdf/co...1fff2acc3670ba

    Execute:
    pvc.setDefaultColorScheme(['red', 'green', 'blue', 'yellow', 'orange', 'purple']);

    somewhere after the CCC script (pvc-d1.0.js) is loaded (like at pre-execution as dguiarj suggested).

    If you can use the DEV version, update the CDF and CGG with the CTools installer and the "-b dev" option. If not, you'll have to wait till the next regular release...
    Last edited by duarte.leao; 07-17-2012 at 06:58 PM.

  4. #4
    Join Date
    Oct 2009
    Posts
    122

    Default

    thanks @
    duarte.leao

  5. #5
    Join Date
    Oct 2009
    Posts
    122

    Default

    Hi @duarte i tried the way you told but not able to succeed. I updated the js file and tried to execute the way you told but its not working for me. Can you tell me some other alternate how to fix a particular color for a particular category of pie chart.

    Thanks

  6. #6
    Join Date
    Mar 2012
    Posts
    129

    Default

    Can you tell me what exactly did not work? Did the function "pvc.setDefaultColorScheme" exist? Was there any error executing the call? The call succeeded but then nothing changed in the colors?
    Anyway, about changing one particular color, that's a different problem.
    You could once again use the "colors" chart option, passed when creating the chart.
    Colors are mapped to categories by order of occurrence in the resultset.
    So, if crosstabMode=false and seriesInRows=false, the nth resultset row will correspond to the nth color in "colors".

  7. #7
    Join Date
    Oct 2009
    Posts
    122

    Default

    Thanks @duarte... for your reply....
    Its a critical issue and blocking the further development. I tried and updated the modification you specified in https://github.com/webdetails/cdf/co...1fff2acc3670ba. pvc.setDefaultColorScheme function exists in the file and there are no error in executing the call, yes the call is succeeding and the colors are not changing, its default color scheme (category10). In my chart properties crosstabMode=false and seriesInRow=false. I have created my own color scheme and passes color option in chart properties chart is rendering fine if all categories are fetched from the query. I have fixed the legend color for the categories as i have to show them separately for all the charts and on click of pie chart my other bar charts get the same color as of pie chart category color. So if i miss a category from the query bar chart colors will get effected.
    I am stuck here please provide a solution for this issue.

    Thanks

  8. #8
    Join Date
    Mar 2012
    Posts
    129

    Default

    About the pvc.setDefaultColorScheme: it is only relevant for when the 'colors' chart option is not specified for a specific chart.
    Anyway, the problem you describe doesn't seem to be fully solvable by the default color scheme.
    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.

  9. #9
    Join Date
    Oct 2009
    Posts
    122

    Default

    Hi,

    I appreciate your guidance in this issue. I am not clear where to write the above code. Is it i have to write it in pre-execution or some where else.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •