Tuesday, February 14, 2012

Colors in legend does not match bar graph

Hi

I have a bar graph with custom colors applied to it.
The custom colors displays nicely in the bar graph, but not in the legend.

The legend displays a mix of some of the "correct" custom colors, and some of the "wrong" standard colors. The colors in the legend vary, depending on the parameters passed to the report. Sometimes legend colors are all right, other times all wrong but must times a mix of right and wrongs.

The value for the custom color of the graph is retrieved from a field in the dataset. However I doubt that this is the cause of the error because, the bar graph colors are correct at all times, and I have validated thet correct color names are actually in the dataset.

Hope someone can help me out with this one...

/Henrik

The legend color always depends on the color of the first datapoint in a chart series.

Also, is a series grouping present in the chart? In that case you have to make sure that e.g. instead of using =Code.PickColor( Fields!ResultSort.Value), you should use this expression that uses the First() aggregate: =Code.PickColor(First(Fields!ResultSort.Value, "chart1_SeriesGroup1")

The important part is the aggregate scope which has to be identical to the chart series grouping name. Just using the First aggregate without the scope will give you incorrect results, because the aggregate will be just scoped for every chart datapoint (and therefore null if you don't have any datapoints for a particular series group / category group combination).

Another option you may consider is using a "custom legend" which is not drawn inside the chart but created by a table besides the chart. My sample and instructions for this can be found in the following blog article:
http://blogs.msdn.com/bwelcker/archive/2005/05/20/420349.aspx

-- Robert

|||

Thanks a lot Robert.
It was the aggregate scope I was missing. It's all working fine now.

/Henrik

|||

Does this apply for Gray Scale? I am having trouble when I set a chart to use Gray Scale the legend shows the first set of patterns but the remaining patterns are all random. I tried adding the scope to the Data section of the chart but it doesn't change the behavior with Gray Scale. Also, if it's a bug, is there a way that I can specify fill patterns in case I write a function to pick the pattern based on the series? Thanks!

No comments:

Post a Comment