我正在尝试显示一个BarChart来显示一些结果,但由于我的结果是非常小的数字,如10 * 10 ^ -10,y轴的比例随着这些值而消失。如何用小数字显示比例?
这是我的代码:
private JPanel createBarChartBER(double ber, double[] calculatedQFactor)
{
double [] berValues = new double[calculatedQFactor.length];
berValues[0]=berCalculation(calculatedQFactor[0]);
berValues[1]=berCalculation(calculatedQFactor[1]);
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(getBer(), "ITU Standards", "ITU Standards");
dataset.addValue(getBer(), "Closest ONU", "Closest ONU");
dataset.addValue(getBer(), "Further ONU", "Further ONU");
// create the chart...
final JFreeChart chart = ChartFactory.createBarChart(
"BER Values", // chart title
"", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips?
false // URLs?
);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
// set the background color for the chart...
chart.setBackgroundPaint(Color.BLACK);
// get a reference to the plot for further customisation...
final CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
// set the range axis to display integers only...
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setRange(0.0, Math.pow(10, -9));
rangeAxis.setTickUnit(new NumberTickUnit(Math.pow(10, -3)));
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setAutoRangeIncludesZero(true);
NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
yAxis.setAutoRangeMinimumSize(Math.pow(10, -3));
yAxis.setTickLabelPaint(Color.WHITE);
rangeAxis.setTickLabelPaint(Color.WHITE);
// disable bar outlines...
final BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setDrawBarOutline(false);
// set up gradient paints for series...
final GradientPaint gp0 = new GradientPaint(
0.0f, 0.0f, Color.blue,
0.0f, 0.0f, Color.white
);
final GradientPaint gp1 = new GradientPaint(
0.0f, 0.0f, Color.green,
0.0f, 0.0f, Color.white
);
final GradientPaint gp2 = new GradientPaint(
0.0f, 0.0f, Color.red,
0.0f, 0.0f, Color.white
);
renderer.setSeriesPaint(0, gp0);
renderer.setSeriesPaint(1, gp1);
renderer.setSeriesPaint(2, gp2);
renderer.setMaximumBarWidth(.1);
final CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(
CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
);
domainAxis.setTickLabelPaint(Color.WHITE);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(400, 300));
chartPanel.setForeground(Color.WHITE);
JPanel jPanel1 = new JPanel();
jPanel1.setLayout(new java.awt.BorderLayout());
jPanel1.add(chartPanel ,BorderLayout.CENTER);
jPanel1.validate();
return jPanel1;
}
答案 0 :(得分:0)
尝试:
axis.setAutoRange(true);
axis.setAutoRangeIncludesZero(false);