Search code examples
reporting-serviceschartsssrs-2008ssrs-2008-r2ssrs-2012

Different color chart


I have 2 kinds of charts,pie chart and column chart.

I present the same data of both charts, the problem is that color that presents each equipment is not the same in both of them.

enter image description here

Thanks


Solution

  • The chart legend uses color fields to match the legend items to the visible data points. The legend can only show one color field per legend item (data series); hence, it shows the color of the first data point within that series. Remember this when you use expressions to dynamically determine the color of individual data points within a series; the legend item always shows the actual color of the first data point.

    Using the same legend order in both charts should do the trick.

    Series are ordered in the legend according to the order that they are processed by the Reporting Services processing engine. You can change the order by changing the order of fields in the data fields drop-zone. If you are using series grouping, the series data is not known until processing, so that there is no way for you to re-order these items.

    If you're using series, which you probably are, you should make sure they're ordered correctly before sending them to the reporter.

    Another solution is to create a custom legend for your charts. Which gives you a lot more control, especially if you define a custom color palette aswell.

    You can get more flexibility and control over the legend by generating your own custom legend by using a table or a matrix. The easiest way to synchronize the colors in the chart with your custom legend is to define your own custom chart color palette.

    To build a custom legend

    1. Add a table data region to the report.
      Place the table next to the chart and bind it to the same dataset as the chart.
    2. Mirror the chart grouping structure in the table by adding table groups.
      If the chart uses series groupings, add them to the table by adding table groups that are based on the same group expression as the one in the chart series groupings. Then add chart category groupings (if present) as inner table groups.

      In general, if the chart has m series grouping and n category grouping, you add m+n table groups for your custom legend.

      For the individual table groups, make sure to show only the group header (which will contain the legend description). Also, remove the table detail row unless you want to use the table detail rows to simulate a chart data table.

    3. Design the custom legend.
      Add a rectangle for the color field of the custom legend. For example, you might add it to the first table column. As indicated in step 2, you should only have group header rows in the table. The rectangle goes into the innermost group header level.

      Set the rectangle BackgroundColor property to the equivalent expression used on the chart data point's fill color. In the most trivial case, the expression would just contain one grouping value as in the following code.

      =Code.GetColor(Fields!Country.Value)
      

      For the legend text, use either the same expression as in the category and series group/label expressions, or experiment until you achieve the legend description text that you want.

    Sources: