Category label on/above bar?
Category label on/above bar?
I would like to have a bar chart with the category labels shown on or on top of the bars instead of below the category axis. Is this possible?
Java 11, JFreeChart 1.0.15, JFreeSVG 4.0
not Possible?
Hi mhilpert.
This works for me, I just want to make the bars wider.
Hope this helps.
Balpo.
Code: Select all
JFreeChart jfreechart = ChartFactory.createBarChart3D("Reglas @Por", "", "Incidencias", categorydataset, PlotOrientation.VERTICAL, true, true, false);
CategoryPlot categoryplot = jfreechart.getCategoryPlot();
categoryplot.setDomainGridlinesVisible(true);
CategoryAxis categoryaxis = categoryplot.getDomainAxis();
categoryaxis.setCategoryLabelPositionOffset(categoryaxis.getMaximumCategoryLabelLines());
categoryaxis.setTickLabelPaint(Color.RED);
BarRenderer3D barrenderer = (BarRenderer3D) categoryplot.getRenderer();
barrenderer.setItemMargin(0.10000000000000001D);
barrenderer.setItemLabelGenerator(new BarChartDemo7.LabelGenerator());
barrenderer.setItemLabelsVisible(true);
barrenderer.setDrawBarOutline(false);
ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER, TextAnchor.CENTER, 0D);
barrenderer.setPositiveItemLabelPosition(itemlabelposition);
ItemLabelPosition itemlabelposition1 = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER, TextAnchor.CENTER, 0D);
barrenderer.setPositiveItemLabelPositionFallback(itemlabelposition1);
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
Hope this helps.
Balpo.