Pie Chart: Color by Categories

edited December 31, 1969 in Designing Analytics Reports
Hi, I'm using a multiple pie charts and the slices are colored based on what the value of the category series is. This is working as intended, but the question I have is can I specify the color based on the value of the category.
For instance, my current slices are 'Agree', 'Disagree' 'Strongly Agree'. Depending on the question, one of these responses may not be in the chart. So a blue slice in Chart A could mean 'Agree', but a blue slice in Chart B could mean 'Disagree', since the slices only look for the category. Is there a way I can specify the coloring to say, if response='Agree' then blue slice, if response='Disagree' then red slice? With multiple charts on a page, users would more than likely get confused seeing the different colors representing the same values.

Thanks,
Bryan

Comments

  • edited December 31, 1969
    Hi,



    Yes. Add this to each of your charts (replace the 'R', 'G', 'B' with the RGB color values)



    function beforeDrawLegendItem( lerh, bounds, icsc )
    {
    var seriesValue = lerh.getLabel().getCaption().getValue();
    var fill = lerh.getFill();

    if( seriesValue == "Agree" )
    fill.set( R, G, B, 255 );
    if( seriesValue == "Disagree" )
    fill.set( R, G, B, 255 );
    if( seriesValue == "Strongly Disagree" )
    fill.set( R, G, B, 255 );
    }

    function beforeDrawDataPoint( dph, fill, icsc )
    {
    if( dph.getBaseDisplayValue() == 'Agree' ){
    fill.set( R, G, B, 255 );
    if( dph.getBaseDisplayValue() == "Disagree" )
    fill.set( R, G, B, 255 );
    if( dph.getBaseDisplayValue() == "Strongly Disagree" )
    fill.set( R, G, B, 255 );
    }



    Hope that helps,

    Rich
  • edited December 31, 1969
    Thanks for the reply Rich, I haven't used the scripting in BIRT much, so I just want to clarify where I'm putting the script. The only place I've really seen scripting is the Script tab in the main view, so does it go there? I currently have the two functions set up on the onRender, which was the only option for the chart. Do I need to replace seriesValue with row['value'], or is it reading seriesValue directly from the pie chart from where I have it set?

    Thanks again,
    Bryan
  • mwilliamsmwilliams BIRT Guru
    edited December 31, 1969
    Yep, you'd just put Rich's script in your chart script by selecting the chart in your layout, then selecting the script tab. The onRender is the only method in the chart. "seriesValue" is being read from the legend label and then the color changed, based on that. You should just need to put this script in the chart's onRender and run it, as long as the category values (Agree, Diagree, Strongly Disagree) are in your chart exactly as Rich put them in the code!

    Regards,

    Michael Williams

    eSignLive Evangelism & Community Manager | eSignLive by VASCO
     
    Find me on:
    Twitter
    Facebook
    Blog
    LinkedIn

    eSignLive Developer Community
     
    Email me:
    Google: [email protected]

  • edited December 31, 1969
    Thanks Rich and Mike, I've got it working now. I had gradients originally for my charts, which was preventing it from changing color based on those values. I'm all good now, thanks again.

    Bryan
Sign In or Register to comment.