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

Message ListMessage List     Post MessagePost Message

  SVG Bar Chart Problem Labels overlap into Chart
Posted by Nicolas K?lmel on Oct-22-2013 21:00
Attachments:
Hi,

we have some issues with the ChartDirector painting bar charts and output SVG. Normal
output works but if we use the enableVectorOutput() method the labels will be slightly
moved into the chart, which we do not want to.

Are there any solutions to this problem?

Thank you very much

Nicolas K?lmel
svgbarchart.PNG
normalbarchart.PNG

  Re: SVG Bar Chart Problem Labels overlap into Chart
Posted by Peter Kwan on Oct-23-2013 00:14
Hi Nicolas,

The issue is due to the different understanding of text width between ChartDirector and the SVG renderer.

As an example, assuming there are two characters, each 2.7 pixels in size, and the spacing between them is 0.7 pixels. To drawing them clearly, ChartDirector will round the character to 3 pixels and the spacing to 1 pixel. So the total text width is 3 + 1 + 3 = 7 pixels. ChartDirector positions and algins the text based on this width.

However, for SVG, the text is "scalable", which means it can be viewed at any arbitrary size. For SVG, it is not useful to round 2.7 "unit" to 3 "unit", because after you scale the SVG, each "unit" may not align with a pixel. So for SVG, the total text width will be treated as 2.7 + 0.7 + 2.7 = 6.1 "units".

Because ChartDirector aligns the text by assuming 7 pixels, but the SVG draws the text as 6.1 units, so the alignment may not be accurate when viewed in SVG. The SVG text can be longer or shorter than the ChartDirector text. Usually, the error is not significant if the text is large. For example, if the text is many pixels wide, then a 0.7 unit error is just a small percentage of the width and is not easy to notice.

For your case, is it that the text in your original chart is very small, so that even small errors become significant? If you intend to output in SVG, try to use a text size is that not small than the normal view size in SVG. In some cases, you may need to add additional margins between the text and the axis to absorb the inaccuracies. (See Axis.setLabelGap.)

Regards
Peter Kwan