JFreeChart在Y轴中将整数值显示为float

时间:2011-12-06 11:43:24

标签: java jfreechart

我使用JFreeChart创建时间序列图表,但是当我将整数值作为Y轴传递时,它将它们显示为浮动!
有什么问题?
我正在创建这样的图表:

this.TodaySeriesGoldPrice = new TimeSeries("Price",Minute.class);
if(TDD!=null){
    for(Map<String, Object> D: TDD){
        Calendar C=Calendar.getInstance();
        C.setTime(new Date((Long)D.get("timestamp")));
        this.TodaySeriesGoldPrice.add(new Minute(C.get(Calendar.MINUTE),C.get(Calendar.HOUR),C.get(Calendar.DAY_OF_MONTH),C.get(Calendar.MONTH),C.get(Calendar.YEAR)),(Integer)(((Map<String,Object>)D.get("tala")).get("Coin")));
    }
}

TimeSeriesCollection TodayDataset = new TimeSeriesCollection();
TodayDataset.addSeries(this.TodaySeriesGoldPrice);
TodayDataset.setDomainIsPointsInTime(true);
JFreeChart chart = ChartFactory.createTimeSeriesChart(
    "", // title
    "Time",// x-axis label
    "Price",// y-axis label
    TodayDataset,// data
    true, // create legend?
    true, // generate tooltips?
    false // generate URLs?
);
chart.setBackgroundPaint(Color.white);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
plot.getDomainAxis().setLabelFont(new Font("Tahoma",Font.PLAIN,13));
plot.getRangeAxis().setLabelFont(new Font("Tahoma",Font.PLAIN,13));
XYItemRenderer r = plot.getRenderer();
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("H:mm"));
ChartPanel DCP=new ChartPanel(chart);
dispPanel.setLayout(new BorderLayout());
dispPanel.add(DCP,BorderLayout.CENTER);

结果:
Result

1 个答案:

答案 0 :(得分:11)

您可以将整数刻度单位强制为:

priceAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

但是,您可以通过覆盖数据集()的getY()来返回整数实例来控制tickunits。