How to conditionally colour a chart?

How to conditionally colour a chart?

Scenario: In a bar chart, you want each bar colour depending on its value.

Solution: Add the chart to the Report, and with the chart selected go to scripts.

Add the following script:


// Apply different colors to the bars depending on their value

private void ApplyTresholdColors(object sender, DevExpress.XtraCharts.CustomDrawSeriesPointEventArgs e) {

var value = Convert.ToDouble(e.SeriesPoint.Values[0]);

if(value<60)

e.SeriesDrawOptions.Color = Color.FromArgb(239, 32, 32);

else if (value>=60 && value<80)

e.SeriesDrawOptions.Color = Color.FromArgb(254, 204, 5);

else

e.SeriesDrawOptions.Color = Color.FromArgb(4, 110, 4);

}


In the Property grid of the chart go to Behavior – Scripts – Custom draw a series and select ApplyTresholdColors from the list of functions in the dropdown menu.


The output chart will be like this:


    • Related Articles

    • How to add an alert label to the chart?

      Scenario: In a chart, you want to show a label with an alert every time a value surpasses a defined threshold. Solution: Replicate the procedure in the previous section, using the function: private void ChangeLabelText(object sender, ...
    • How to create a chart with auto created series?

      Scenario: you have this bar chart in QlikView. The straight table for it is this one, with one column for type, one for date, and one for number. You cannot use series to create that chart in BIReport, since you do not have a column for each type. ...