oxyplot icon indicating copy to clipboard operation
oxyplot copied to clipboard

Bar chart x-axis labels overlapping

Open doorman02 opened this issue 4 years ago • 9 comments

Steps to reproduce

  1. Bar chart with four legends
  2. Each bar has a label on the x-axis. The label has a \r\n to divide it into two lines
  3. Legends are located below the labels (BottomCenter)
  4. If the legend names are too long they are rendered into two lines
  5. This causes the x-axix labels undir each bar to overlap it's content e.g. if a x-axis label is "Testing \r\n Hello World" the label is rendered in two lines. However the "Hello World" part would overlap "Testing" in the first line.

Platform: Windows 10 .NET version: .NET 4.7.2

Expected behaviour

The x-axis two lines label should not overlap when the below legends are rendered in two lines.

Actual behaviour

The x-axis two lines label overlap when the below legends are rendered in two lines.

image

doorman02 avatar Jul 08 '21 09:07 doorman02

Is this WPF/Winforms or one of the exporters?

This looks like the sort of problems we get with the default SVG exporter (the solution generally to use a platform specific SVG Exporter e.g. OxyPlot.WindowsForms.SvgExporter).

VisualMelon avatar Jul 08 '21 09:07 VisualMelon

Hi @VisualMelon we are using the SvgExporter to export to pdf.

doorman02 avatar Jul 08 '21 09:07 doorman02

Which SVG exporter specifically? If you are using OxyPlot.SvgExporter at the moment, can you use e.g. OxyPlot.WindowsForms.SvgExporter as indicated above? (it has better support for test measurement). If that doesn't help, then I'll take a closer look over the weekend when I have more time.

VisualMelon avatar Jul 08 '21 09:07 VisualMelon

Thanks for your help. Yes, we are using OxyPlot.SvgExporter inside a .NET Web API and the logic is inside a netstandard2 library. So we can't use OxyPlot.WindowsForms.SvgExporter The client side application is an angular app.

doorman02 avatar Jul 08 '21 09:07 doorman02

OK, there probably won't be an easy solution then; the built-in SVG and PDF exporters doesn't have good font support, and we aren't really intending to work on them.

If you need this in a netstandard 2.0 library, then you could use the OxyPlot.SkiaSharp provision in the pre-release (which has a native though slightly less feature-complete (in terms of what OxyPlot needs) SVG exporter. Alternatively, it should be possible to use the ImageSharp provision for text measuring (I have some code lying around for this, but I can't remember how if it works).

It's been a long time since I buried my head in this stuff, if you are happy to bodge it slightly, you could override the built-in PdfRenderContext (which is the text-renderer used by OxyPlot.SvgExporter and inflate the text measurements somewhat.

(I'm happy to help with any of these options, time permitting)

VisualMelon avatar Jul 08 '21 09:07 VisualMelon

Thanks for the information, we will probably just shorten the text to make it fit.

doorman02 avatar Jul 08 '21 11:07 doorman02

@doorman02 does throwing in an extra pair of \r\n help? (or is that excessive?)

VisualMelon avatar Jul 08 '21 11:07 VisualMelon

@VisualMelon thanks that worked 👍

doorman02 avatar Jul 09 '21 12:07 doorman02

I will leave the bug open in case any work is needed.

doorman02 avatar Jul 09 '21 12:07 doorman02