XChart icon indicating copy to clipboard operation
XChart copied to clipboard

Annotation in CategoryChart always inside of bars

Open arospatricio opened this issue 5 years ago • 7 comments

I've been trying to make the annotations in the CategoryChart to be always outside the bars but im getting this result:

ApplicationFrameHost_JMWVa2wFVh

i followed the example codes in the XChart Website

This is my code:

Font font = new Font("Arial", Font.PLAIN, 12);

CategoryChart chart = new CategoryChartBuilder().width(800).height(600).title(tituloGrafico).xAxisTitle(nombreEjeX).yAxisTitle(nombreEjeY).theme(ChartTheme.GGPlot2).build();
chart.getStyler().setChartBackgroundColor(ChartColor.getAWTColor(ChartColor.WHITE));
chart.getStyler().setPlotBackgroundColor(ChartColor.getAWTColor(ChartColor.WHITE));
chart.getStyler().setChartTitleBoxBackgroundColor(ChartColor.getAWTColor(ChartColor.WHITE));
chart.getStyler().setChartTitleBoxBorderColor(ChartColor.getAWTColor(ChartColor.WHITE));
chart.getStyler().setChartTitleBoxVisible(false);
chart.getStyler().setLegendVisible(true);
chart.getStyler().setLegendPosition(LegendPosition.InsideNW);
chart.getStyler().setHasAnnotations(true);
chart.getStyler().setAnnotationsPosition(1);
chart.getStyler().setShowTotalAnnotations(true);
chart.getStyler().setBaseFont(font);

As you can see im using chart.getStyler().setAnnotationsPosition(1); to force the annotation to be at the top (and i think outside the bars). After this im jut going adding the series in a for loop like this

chart.addSeries(datosSeriesHistograma.get(i).getNombreSerie(), Arrays.asList(serieX),Arrays.asList( serieY)).setFillColor(new Color(datosSeriesHistograma.get(i).getColorSerie().getRed(), datosSeriesHistograma.get(i).getColorSerie().getGreen(),datosSeriesHistograma.get(i).getColorSerie().getBlue()));

Is this some kind of "error" or am i making a something wrong?

arospatricio avatar Jan 07 '21 15:01 arospatricio

Hi, I have a big issue for Category's annotations. I don't understand how to have on the top bars annotations (globalAnnotations) and haven't any annotations inside the bars. Can I manage in some way this requirement?

Another issue for Category If I have a big number the numbers exceds from margin bars. How I can resolve?

Thank in advance

andreapagliacci avatar Jan 13 '21 16:01 andreapagliacci

Hi Thanks. I'm looking into it...

timmolter avatar Jan 15 '21 11:01 timmolter

Right now this feature is not supported. I will leave this open as a feature request...

timmolter avatar Jan 20 '21 09:01 timmolter

I'm pretty sure its a bug (this, just if im not doing something wrong). The annotations in the examples page are outside the bars in the categorychart (basic bar chart).

imagen

arospatricio avatar Jan 22 '21 18:01 arospatricio

yeah, it's a bug. I'll add the bug tag.

timmolter avatar Jan 23 '21 17:01 timmolter

Not sure if this is documented anywhere, but currently setAnnotationsPosition taking values from the range of [0.0, 1.0] is for placing the values within the bar. 0 makes it, the lowest possible place within the bar. 1 makes it the highest possible place within the bar.

So, in order to support placing the values outside of the bar I see several options for the API:

  • change semantics of 1.0 to mean "just above the bar"
  • allow for values outside of the range [0.0, 1.0], so that people can specify e.g. 1.1 (would most likely look ugly)
  • add another method, e.g. setAnnotationsPositionOutside(boolean) or something similar, the current setAnnotationsPosition would only be used if the new property is set to false
  • ... else?

@timmolter what should happen here?

mccartney avatar Feb 02 '21 20:02 mccartney

The 1.1 idea is ugly. I tried that. Whatever the solution it has to be a fixed distance, say 4 pixels above the bar. I think the best would be:

chart.getStyler().setLabelsOutside(true)

timmolter avatar Feb 02 '21 21:02 timmolter