ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  LegendBox color difference in Bar Chart
Posted by Adrian on Sep-07-2011 05:26
Attachments:
Hi,

I have a question regarding the colors on the little squares of a LegendBox.  Take a look at my image, which contains 3 different legends each for a different chart.

The first  rectangle is the legend for a Bar Chart.
The second rectangle is the legend for a Line Chart.
The third  rectangle is the legend for a Area Chart.

You can see the Line and Area Chart appear identical. But the Bar chart, for some reason, the border around the little squares is different. Its like there is no border. The code I'm using for all three is below. As you can see, its the same code. I'd like the bar chart legend little squares to appear the same as the rest. The data and size was exactly the same for all charts.

Any ideas why this would be doing this?

// Bar Legend Code
LegendBox legendBox = c.addLegend(plot.get("xLegend"), plot.get("yLegend"), false,
     ChartUtil.fontType(getFonttypelabel()), ChartUtil.ideaLegendFontSize(super.getWidth(), super.getHeight()));
legendBox.setBackground(Chart.Transparent, Chart.Transparent);

// Line Legend Code
LegendBox legendBox = c.addLegend(plot.get("xLegend"), plot.get("yLegend"), false,
     ChartUtil.fontType(getFonttypelabel()), ChartUtil.ideaLegendFontSize(super.getWidth(), super.getHeight()));
legendBox.setBackground(Chart.Transparent, Chart.Transparent);

// Area Lagend Code
LegendBox legendBox = c.addLegend(plot.get("xLegend"), plot.get("yLegend"), false,
     ChartUtil.fontType(getFonttypelabel()), ChartUtil.ideaLegendFontSize(super.getWidth(), super.getHeight()));
legendBox.setBackground(Chart.Transparent, Chart.Transparent);
check.PNG

  Re: LegendBox color difference in Bar Chart
Posted by Peter Kwan on Sep-08-2011 00:21
Hi Adrian,

ChartDirector will attempt to draw the legend icon to represent the actual shape displayed.

For a bar chart, the icon will be a polygon of the same shape as the bar (ChartDirector supports using rectangular, circular as well as polygonal bars - see the "Multi-Shape Bar Chart" sample code). The fill and edge color of the polygon will be the same as the fill and edge color of the bar. So if you are using a rectangular bar with a fill color, but no edge color, then the legend icon will be a rectangle with a fill color but no edge color.

For a line chart, if the line does have style or symbols (eg. dash line style, or using a dot as the data point symbol), ChartDirector will use a legend icon that is a line shape, of the same thickness and line style as the actual line, and will a data point symbol if the actual line uses symbols. However, for compatibility with previous versions of ChartDirector, if the line does not have style or symbols, ChartDirector will just draw a rectangle with border as the legend icon. If you always want the legend icon to show a line for a line chart, you can disable this compatibility feature by using LegendBox.setLineStyleKey. For example:

legendBox.setLineStyleKey(true);

Other type of layers may have icons of other shapes. For example, a scatter layer will use icons that resembles the scatter symbols. A vector layer will use an arrow as the legend icon, etc.. For an area layer, it will use a rectangle with border as the legend icon.

If you always want the legend icon to be a fill rectangle with black border, but you can have many chart types with various display styles, you may consider the following method:

(a) For all the layers you added to the chart, use Layer.setLegendOrder to display the automatic legend entries:

myLayer.setLegendOrder(Chart.NoLegend);

(b) For each data set your code adds to your chart, your code would also add a legend entry using the following code:

legendBox.addKey(myDataSetName, myColor);

Hope this can help.

Regards
Peter Kwan