最近做项目使用到了JFreechat,不知道如何在曲线图中显示百分比,请各位指教.
我的代码大概如下:
JFreeChart chart = ChartFactory.createLineChart(title,
XLable, // 目录轴的显示标签
YLable, // 数值轴的显示标签
dataset, // 数据集
PlotOrientation.VERTICAL, true, false)
false, // 是否生成工具
false // 是否生成URL链接
);
NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis();
numberaxis.setAutoTickUnitSelection(true);
在一个帖子上看到要这样设置:numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()) ;
但是仍然没有显示百分比,请高手指教,我应该如何处理?非常感谢!!
我的代码大概如下:
JFreeChart chart = ChartFactory.createLineChart(title,
XLable, // 目录轴的显示标签
YLable, // 数值轴的显示标签
dataset, // 数据集
PlotOrientation.VERTICAL, true, false)
false, // 是否生成工具
false // 是否生成URL链接
);
NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis();
numberaxis.setAutoTickUnitSelection(true);
在一个帖子上看到要这样设置:numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()) ;
但是仍然没有显示百分比,请高手指教,我应该如何处理?非常感谢!!
之类的,可以自定义标签产生方式,具体的你自己找吧。
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(bean.getYValue()(double类型,纵坐标,需要显示百分比), bean.getTitle()(String类型), bean.getXValue()(String类型,横坐标));
plot是这个.
CategoryPlot plot = chart.getCategoryPlot();
我把代码再次重新整理一下.
Chart是这样的
JFreeChart chart = ChartFactory.createLineChart(title,
XLable, // 目录轴的显示标签
YLable, // 数值轴的显示标签
dataset, // 数据集
PlotOrientation.VERTICAL, true, false)
false, // 是否生成工具
false // 是否生成URL链接
);
DataSet是这样的.
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(bean.getYValue()(double类型,纵坐标,需要显示百分比), bean.getTitle()(String类型), bean.getXValue()(String类型,横坐标));
plot 是这个:CategoryPlot plot = chart.getCategoryPlot();请高手指教,希望能给出代码.
我在一个帖上查了代码,有的代码到我这里不能执行,可能是plot类型以及dataSet类型用的不一样吧. 所以希望能给出代码,谢谢!!