Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JFreeChart Displays integer values as float in Y-Axis

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

Result:
Result

like image 931
Ariyan Avatar asked Dec 06 '11 11:12

Ariyan


1 Answers

You can force integer tick units as:

priceAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

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

like image 185
Ashwinee K Jha Avatar answered Sep 19 '22 00:09

Ashwinee K Jha