通过使用StandardCategoryItemLabelGenerator()Iam能够显示一个栏上的精确范围轴值,现在我的问题是我不想显示范围轴值,而是我想显示该栏的其他值我如何实现这一目标?如何使用jfree图表在条形图中的条形图上显示自定义值?
for (String IDS : idMap.keySet()) {
List<String> listValues = idMap.get(IDS);
if(listValues != null && listValues.get(1) != null) {
dataSet.setValue(Double.valueOf(listValues.get(1)), "", IDS);
}
}
JFreeChart chart = ChartFactory.createBarChart3D("", "", "Time taken ", dataSet,PlotOrientation.VERTICAL, true, true, false);
chart.setTitle(new org.jfree.chart.title.TextTitle("Time Duration",new java.awt.Font("SansSerif", java.awt.Font.BOLD, 10)));
chart.getLegend().setItemFont(new java.awt.Font("SansSerif",0,7));
chart.removeLegend();
final CategoryPlot plot = chart.getCategoryPlot();
plot.setNoDataMessage("No data available");
final CategoryItemRenderer renderer = plot.getRenderer();
renderer.setItemLabelsVisible(true);
final BarRenderer r = (BarRenderer) renderer;
r.setMaximumBarWidth(0.05);
r.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
r.setBaseItemLabelsVisible(true);
r.setSeriesItemLabelFont(0, new java.awt.Font("Times New Roman",Font.NORMAL,7));
r.setSeriesPositiveItemLabelPosition(0,
new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.BOTTOM_LEFT, TextAnchor.BOTTOM_LEFT, -Math.PI/2));
final ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setLabelFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 8));
final CategoryAxis axis = plot.getDomainAxis();
axis.setLabel("ids");
axis.setLabelFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 8));
axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI/8.0));
axis.setTickLabelFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 6));
plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinesVisible(true);
通过使用上述代码亚姆能够棒上显示确切范围轴值,但我不想要的范围轴值我需要一些其它值listValues.get(2)要被显示的条上如何我能做到吗?
请修改您的问题,以包含修改后的代码作为[sscce](http://sscce.org/),它表现出您描述的问题。 – trashgod
对上述评论感到抱歉。实际上,generateLabelString()接受数据集,行,列作为参数,如何在列上传递listValues.get(2)以显示listValues.get(2)。 – satish
您可以将地图作为参数传递给您的生成器的构造函数,并查找第二个值。 – trashgod