Adding conditional color fill to a chart

Usually, for a data marker in a chart, it uses a predefined color pattern assigned by JReport. However, by using the Conditional Color Fill feature, you can assign color patterns based on different value ranges. Thus, with the distinguishing colors, it is easy for you to locate the values you need to focus on in a chart.

There are two types of conditional color fill settings: Single Color with Condition and Multiple Colors with Condition. With a single color, you can make the data marker that meets the specified condition apply the color pattern bound with the condition. By using multiple colors, you can divide each data marker into different parts based on different value ranges along the direction of the value axis, and then specify different conditional colors to different value ranges.

Conditional color fill is only supported on bar, bench, pie, donut, area (Area 2-D and Area 3-D types), and 2-D line charts.

To adding conditional color fill to a chart:

  1. Double-click on any data marker (bar, bench, pie, donut, or line), and the corresponding format dialog is displayed.
  2. Switch to the Fill tab (for line chart, to the Node tab). See a sample dialog.

  3. Select the fill type: Use Single Color with Condition or Use Multiple Colors with Condition. The fill type Use Multiple Colors with Condition is only supported on Clustered Bar/Bench 2-D, Clustered Bar/Bench 3-D, Bar/Bench 3-D, Area 2-D and Area 3-D chart types.
  4. If you select Use Single Color with Condition, you can edit the conditional fill with two modes (to switch between the two modes, click the Advanced or Normal button):

    If you select Use Multiple Colors with Condition, click button to add a condition line. Specify the start value and end value for the condition by inputting the values directly in the text boxes, then set the color and transparency for the value range. Click to add another condition and define the color pattern for it. The value beyond the ranges you have defined in all your conditions will automatically use color pattern defined in the Other condition line. By default, the condition expression of the condition line will be shown as the legend entry label. If you want to change it, select the condition line, check Label, and then change the label in the text box that follows.

  5. When done, click OK to accept the settings and close the dialog.

Examples of adding conditional color fill to a chart

The following examples illustrate how to add conditional color fill to a chart.

Using the Use Single Color with Condition fill type
  1. Open the catalog file SampleReports.cat.
  2. Click File > New > Page Report on the menu bar. Select Chart in the New Page Report dialog and click OK to bring out the Chart Wizard.
  3. In the Data screen of the wizard, select the query WorldWideSales from Data Source 1. Then click Next.
  4. Select Clustered Pie type in the Type screen.
  5. In the Display screen, add the field City to the Category box, then click the Order/Select N button. In the Category Options dialog, select Top N from the Select drop-down list, input 12 in the text field to the right, then click OK to return to the wizard. Add the field Sum_TotalSalesbyCity to the Show Values box.
  6. Skip the Filter, Layout and Style screen, click Finish to create the chart.
  7. Save the report and click the View tab, the report will show as follows:

  8. Go back to the design mode and double-click a pie in the chart. The Format Pie dialog will be displayed.
  9. Go to the Fill tab and select Use Single Color with Condition. From the Select Field drop-down list, select [Category]City, then click the add button three times to add three condition lines, and specify the conditions and related colors as follows:

  10. Click OK to apply the settings and close the dialog.
  11. View the report again. Now you can see pie sections standing for the city Almaty, Brussels and Beijing are filled with the defined color for distinguishing, and other cities are all be distributed to the Other group.

Next, we will use percentage values to edit the condition expressions.

  1. Go back to the design mode and enter the Format Pie dialog again.
  2. Select Use Single Color with Condition again in the Fill tab, then select [Value]Sum_TotalSalesbyCity from the Select Field drop-down list. Check the Percent radio button, and click to add a new condition line. Set the start value to 0.04, and the end value to 0.06, and then input 00CCFF in the Color text field. Check the Label checkbox, then modify the condition expression to 4% <= TotalSales < 6%. Specify the color for the Other group to FFFF99. Click OK to accept the settings. View the report and the result looks like:

  3. From the report above, you can see the Other group and all the pie sections whose values are between 4% and 6% of the total value are filled with the defined colors. To make the result more clear, you can specify to display the value label of the pies in percent by setting the property Value Label Type of the chart paper to percent in the Report Inspector. Then the report result is shown as follows:

Using the Use Multiple Colors with Condition fill type
  1. Open the catalog file SampleReports.cat, and create a clustered bar 2-D chart using the same query, category/value field and the Select N condition with the pie chart above. View the report and it looks like as follows:

  2. Double-click a bar in the chart to display the Format Bar dialog.
  3. In the Fill tab, select Use Multiple Colors with Condition as the fill type, then the value field Sum_TotalSalesbyCity will be the selected by default in the Select Field drop-down list. Click four times to add four condition lines, then specify the conditions and the colors as follows:

  4. By default, the condition expression will be used as the legend entry label. Take the first condition line as example, its condition expression is 10000 <= Sum_TotalSalesbyCity < 20000, which is not very intuitive. To change it, select the condition line, check the Label checkbox, then change the expression to 10000 <= TotalSales < 20000 in the Label text field. Make the similar changes to all the condition lines and click the OK button.
  5. Save the report and click the View tab, the result will be displayed as follows. Each bar is divided into several parts based on different value ranges with different conditional colors.