描述: 我从数据库中获取数据,进行某些计算以获得百分比,然后将百分比添加到addValue方法。 计算的百分比例如是双倍百分比= 0.068172;
现在下面是设置上述百分比的代码;
datasetAnnual.addValue(percentage, TTNIConstants.PERNCENTAGE,
String.valueOf(year_2));
getAnnualChart(datasetAnnual);
问题是:上述percnetage值最多返回3位十进制数。在这种情况下,数据是0.068。但我需要它达到4位十进制数,即在这种情况下我期待0.0681; 图表显示0.068,但我希望它为0.0681。
addValue()方法是否只占用最多3位小数?或者我应该写一些额外的代码?
非常感谢您的帮助。
这就是我设置数据集和创建图表的方式
public JFreeChart getAnnualChart(DefaultCategoryDataset datasetAnnual){
JFreeChart annualChart = ChartFactory.createLineChart(
" Title-1", "Title-2", "Title-3",
datasetAnnual, PlotOrientation.VERTICAL, true,
// false)
false,
false
);
System.out.println(datasetAnnual.getValue(0, 0));
CategoryAxis domainAxis1 = plot1.getDomainAxis();
domainAxis1.setTickLabelFont(new Font("Arial", Font.BOLD, 12));
plot1.setDomainGridlinePaint(Color.BLACK);
plot1.setDomainGridlinesVisible(true);
plot1.setRangeGridlinePaint(Color.RED);
plot1.setRangeGridlinesVisible(true);
plot1.setBackgroundPaint(new Color(204, 255, 153));
plot1.setOutlineVisible(true);
plot1.setOutlinePaint(Color.magenta);
// ValueAxis rangeAxis1 = plot1.getRangeAxis();
NumberAxis rangeAxis = (NumberAxis) plot1.getRangeAxis();
//rangeAxis1.setUpperMargin(0.15);
rangeAxis.setLowerMargin(0.15);
rangeAxis.setLowerBound(0);
rangeAxis.setUpperBound(1.095);
rangeAxis.setTickLabelFont(new Font("Arial", Font.BOLD, 12));
rangeAxis.setLabelFont(new Font("Arial", Font.BOLD, 12));
rangeAxis.setAutoRangeMinimumSize(4);
rangeAxis.setTickUnit(new NumberTickUnit(0.1, new DecimalFormat("##,##,##0%")));
annualChart.getLegend().setPosition(RectangleEdge.RIGHT);
LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
renderer1.setBaseOutlinePaint(Color.ORANGE);
renderer1.setDrawOutlines(true);
renderer1.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer1.setBaseItemLabelsVisible(true);
/*renderer1.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}"
, NumberFormat.getNumberInstance()));*/
renderer1.setBaseItemLabelFont(new Font("bold", Font.CENTER_BASELINE,
12));
renderer1.setBaseItemLabelPaint(Color.BLUE);
renderer1.setBasePositiveItemLabelPosition(new ItemLabelPosition(
ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));
plot1.setRenderer(renderer1);
return annualChart;
}