Hi all,
I'm new to JFree Chart. And I'm trying to construct one with months [jan, feb, mar, ...] as the x axis
and double values (balances) for those months .
the problem is that i need only months on the x- axis.
i tried this :
public JFreeChart createChart(String title) {
TimeSeries time = new TimeSeries("Annual", "Month", "Value", Year.class);
time.add(new Month(Month.JANUARY ,null), new Double(50.1));
time.add(new Month(Month.FEBRUARY ,null), new Double(62.1));
time.add(new Month(Month.MARCH ,null), new Double(15.1));
time.add(new Month(Month.APRIL ,null), new Double(59.1));
time.add(new Month(Month.MAY ,null), new Double(43.1));
time.add(new Month(Month.JUNE ,null), new Double(95.1));
time.add(new Month(Month.JULY,null), new Double(19.1));
time.add(new Month(Month.AUGUST,null), new Double(29.1));
TimeSeriesCollection timeData = new TimeSeriesCollection(time);
timeData.setDomainIsPointsInTime(false);
JFreeChart chart = ChartFactory.createXYBarChart(
title,
"Periods",
true,
"Balances",
timeData,
PlotOrientation.VERTICAL,
true,
false,
false
);
return chart;
}
but didn't work out .
i know this might silly thread ^^", but to me help is highly appreciated
thanks in advance.
Bar Chart with months and double values only
Re: Bar Chart with months and double values only
You don't need a time series for this, just use DefaultCategoryDataset for your bar chart.
Make sure you add values to the dataset in the order from Jan to Dec.
It would be something like this:
Make sure you add values to the dataset in the order from Jan to Dec.
It would be something like this:
Code: Select all
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(1.0, "series 1", "Jan");
dataset.addValue(2.0, "series 1", "Feb");
dataset.addValue(3.0, "series 1", "Mar");
dataset.addValue(4.0, "series 1", "April");
dataset.addValue(5.0, "series 1", "May");
...
JFreeChart chart = ChartFactory.createBarChart(
"Title",
"Month",
"Value",
dataset,
PlotOrientation.VERTICAL,
true,
true,
false
);