JFreeChart将整数值显示为Y轴上的浮点数 [英] JFreeChart Displays integer values as float in Y-Axis

查看:60
本文介绍了JFreeChart将整数值显示为Y轴上的浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using JFreeChart to create a Time Series Chart but while I'm passing Integer values as Y-Axis it shows them as float!!
what is the problem?
I'm Creating chart like this:

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);

结果:

推荐答案

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

You can force integer tick units as:

priceAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

但是,您有可能可以通过重写Dataset()的getY()以返回Integer的实例来控制滴答单位.

However it may be possible that you can control the tickunits by overriding getY() of your Dataset() to return instance of Integer.

这篇关于JFreeChart将整数值显示为Y轴上的浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆