gpt4 book ai didi

java - JFreeChart y 轴图例随着小数字消失

转载 作者:太空宇宙 更新时间:2023-11-04 14:08:12 26 4
gpt4 key购买 nike

我正在尝试显示条形图来显示一些结果,但因为我的结果是非常小的数字,例如 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;
}

最佳答案

尝试:

axis.setAutoRange(true);
axis.setAutoRangeIncludesZero(false);

关于java - JFreeChart y 轴图例随着小数字消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28633313/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com