我在Axis上有问题,JFreeChart上的工具提示显示他们没有显示所有值,我试图根据日常使用显示字节,这是一个图像来显示我的问题:
缺少一些值,在最高的红色条上,它没有显示工具提示上的字节。这是我的代码:
final JFreeChart chart = createTrafficChart();
chartPanel = new ChartPanel(chart, true, true, true, true, true);
chartPanel.setPreferredSize(new java.awt.Dimension(750, 367));
a.gridx = 0;
a.gridy = 3;
jpContainer.add(chartPanel, a);
private JFreeChart createTrafficChart() {
// create plot ...
final IntervalXYDataset data1 = createDatasetDownload();
XYBarRenderer t= new XYBarRenderer(0.20);
t.setShadowVisible(false);
final XYItemRenderer renderer1 = t;
renderer1.setBaseToolTipGenerator(new MyTrafficToolTipGenerator());
final DateAxis domainAxis = new DateAxis("Date");
domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
final NumberAxis rangeAxis = new NumberAxis("Bytes");
setupRangeAxis(rangeAxis);
final XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1);
// add a second dataset and renderer...
final XYDataset data2 = createDatasetUpload();
final XYItemRenderer renderer2 = new StandardXYItemRenderer();
renderer2.setBaseToolTipGenerator(new MyTrafficToolTipGenerator());
plot.setDataset(1, data2);
plot.setRenderer(1, renderer2);
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
return new JFreeChart("Traffic", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
这段代码:
public void setupRangeAxis(NumberAxis rangeAxis) {
final TickUnits standardUnits = new TickUnits();
standardUnits.add(new MyNumberTickUnit(1));
standardUnits.add(new MyNumberTickUnit(10));
standardUnits.add(new MyNumberTickUnit(100));
standardUnits.add(new MyNumberTickUnit(1024)); // Kilo
standardUnits.add(new MyNumberTickUnit(10000));
standardUnits.add(new MyNumberTickUnit(100000));
standardUnits.add(new MyNumberTickUnit(1024*1024)); // Mega
standardUnits.add(new MyNumberTickUnit(10000000));
standardUnits.add(new MyNumberTickUnit(100000000));
standardUnits.add(new MyNumberTickUnit(1024*1024*1024)); // Giga
standardUnits.add(new MyNumberTickUnit(10000000000L));
standardUnits.add(new MyNumberTickUnit(100000000000L));
standardUnits.add(new MyNumberTickUnit(1024*1024*1024*1024)); // Tera
standardUnits.add(new MyNumberTickUnit(10000000000000L));
standardUnits.add(new MyNumberTickUnit(100000000000000L));
standardUnits.add(new MyNumberTickUnit(1000000000000000L)); // Peta
standardUnits.add(new MyNumberTickUnit(10000000000000000L));
standardUnits.add(new MyNumberTickUnit(100000000000000000L));
standardUnits.add(new MyNumberTickUnit(1000000000000000000L)); // Exa
rangeAxis.setStandardTickUnits(standardUnits);
}
我找到了here。 我也有这个代码:
public class MyNumberTickUnit extends NumberTickUnit{
private static final long serialVersionUID = 4281451255133640119L;
public MyNumberTickUnit(double size) {
super(size);
}
public String valueToString(double value){
return StringFormat.formatTheTraffic(value);
}
}
public class StringFormat {
public static String formatTheTraffic(double input) {
String result = "";
if (input < KILO_BYTES) {
result = input + " Byte";
} else if ((input < MEGA_BYTES) && (input >= KILO_BYTES)) {
result = new DecimalFormat("##.#").format(input / KILO_BYTES) + " KB";
} else if ((input < GIGA_BYTES) && (input >= MEGA_BYTES)) {
result = new DecimalFormat("##.#").format(input / MEGA_BYTES) + " MB";
} else if ((input < TERA_BYTES) && (input >= GIGA_BYTES)) {
result = new DecimalFormat("##.#").format(input / GIGA_BYTES) + " GB";
}
return result;
}
}
感谢您的关注和时间!
答案 0 :(得分:0)
我发现了我的问题。它在formatTheTraffic方法里面!我现在改变它并正常工作!