Jfree将自定义名称用于类别

时间:2012-06-12 07:24:19

标签: jfreechart jspx jfreereport

我是Jfreechart的新手,请帮我解决这个问题,我正在使用jfree为具有特定代码名称的类别绘制图形,如563,258.855等...所以我想分配这些值作为域轴的标签,但默认情况下,它将value1,value2,value3等分配给类别。 It is looking like this now

但我想做到类似下面的东西 enter image description here

这是我的代码,

final CategoryDataset dataset1 = DatasetUtilities.createCategoryDataset("Month to Date Occurences","value", data);  


JFreeChart dualchart = ChartFactory.createBarChart(
    "Top Ten Diagnostic Occurences",         // chart title
    "Category",                 // domain axis label
    "Score",                // range axis label
    dataset1,                    // data
    PlotOrientation.HORIZONTAL, // orientation
    true,                       // include legend
    true,
    false
);



CategoryPlot plot = dualchart.getCategoryPlot();
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
plot.setBackgroundPaint(Color.WHITE);
plot.setRangeGridlinePaint(Color.black); 


BarRenderer renderer= (BarRenderer) plot.getRenderer();
renderer.setItemMargin(0.0);


CategoryAxis domainAxis = plot.getDomainAxis ();
domainAxis.setCategoryMargin(0.30); //distance between series
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setRange(0.0, 100.0);
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

return dualchart;

欢迎您提出建议, 提前致谢。

1 个答案:

答案 0 :(得分:1)

你没有包含dataset1的代码所以很难说出问题是什么,但如果你使用这样的东西:

private static CategoryDataset createDataset() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(15, "1", "451");
    dataset.addValue(12, "1", "851");
    dataset.addValue(10, "2", "362");
    dataset.addValue(5,  "2",  "142");   
    return dataset;
}

你会得到一个这样的图表:

enter image description here