Hi every body,
I am looking an example of Bar Chart(between value and time). I have explored the JFreeChart but there is example of Bar Chart(between value and category). Can any body provide me the usefull information or example?
Thanks
Best regards,
example of Bar Chart(between value and time)?
Time is relative
Time changes...
So time = ?, Years, Months, Days, Seconds, Milliseconds...?
(btw i never use the supplied default datasets/dataseries, it is much better to implement your own)
So time = ?, Years, Months, Days, Seconds, Milliseconds...?
Code: Select all
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.TooltipChartPanel;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.DateTickMarkPosition;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYBarRenderer;
import org.jfree.data.time.*;
import org.jfree.data.xy.XYDataset;
import javax.swing.*;
import java.awt.*;
public class BarChartTime extends JFrame {
public BarChartTime() {
super("BarChartTime");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DateAxis domainAxis = new DateAxis("Date");
NumberAxis rangeAxis = new NumberAxis("y");
XYBarRenderer renderer = new XYBarRenderer(0.1);
XYDataset dataset = getMonthDataset();
// XYDataset dataset = getDayDataset();
// XYDataset dataset = getSecondDataset();
XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
mainPlot.setDomainGridlinesVisible(true);
domainAxis.setTickMarkPosition( DateTickMarkPosition.MIDDLE );
JFreeChart chart = new JFreeChart(null, null, mainPlot, false);
ChartPanel chartPanel = new TooltipChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(800, 300));
this.add(chartPanel);
this.pack();
}
private XYDataset getMonthDataset() {
TimeSeries s1 = new TimeSeries("Series 1", Month.class);
s1.add(new Month(1, 2001), 142);
s1.add(new Month(2, 2001), 181);
s1.add(new Month(3, 2001), 167);
s1.add(new Month(4, 2001), 153);
s1.add(new Month(5, 2001), 167);
s1.add(new Month(6, 2001), 158);
s1.add(new Month(7, 2001), 148);
s1.add(new Month(8, 2001), 153);
s1.add(new Month(9, 2001), 142);
s1.add(new Month(10, 2001), 123);
s1.add(new Month(11, 2001), 131);
s1.add(new Month(12, 2001), 139);
final TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(s1);
return dataset;
}
private XYDataset getDayDataset() {
TimeSeries s1 = new TimeSeries("Series 1", Day.class);
s1.add(new Day(1, 1, 2001), 142);
s1.add(new Day(2, 1, 2001), 181);
s1.add(new Day(3, 1, 2001), 167);
s1.add(new Day(4, 1, 2001), 153);
s1.add(new Day(5, 1, 2001), 167);
s1.add(new Day(6, 1, 2001), 158);
s1.add(new Day(7, 1, 2001), 148);
s1.add(new Day(8, 1, 2001), 153);
s1.add(new Day(9, 1, 2001), 142);
s1.add(new Day(10, 1, 2001), 123);
s1.add(new Day(11, 1, 2001), 131);
s1.add(new Day(12, 1, 2001), 139);
final TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(s1);
return dataset;
}
private XYDataset getSecondDataset() {
TimeSeries s1 = new TimeSeries("Series 1", Second.class);
s1.add(new Second(1, 1, 1, 1, 1, 2001), 142);
s1.add(new Second(2, 1, 1, 1, 1, 2001), 181);
s1.add(new Second(3, 1, 1, 1, 1, 2001), 167);
s1.add(new Second(4, 1, 1, 1, 1, 2001), 153);
s1.add(new Second(5, 1, 1, 1, 1, 2001), 167);
s1.add(new Second(6, 1, 1, 1, 1, 2001), 158);
s1.add(new Second(7, 1, 1, 1, 1, 2001), 148);
s1.add(new Second(8, 1, 1, 1, 1, 2001), 153);
s1.add(new Second(9, 1, 1, 1, 1, 2001), 142);
s1.add(new Second(10, 1, 1, 1, 1, 2001), 123);
s1.add(new Second(11, 1, 1, 1, 1, 2001), 131);
s1.add(new Second(12, 1, 1, 1, 1, 2001), 139);
final TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(s1);
return dataset;
}
public static void main(String[] args) {
new BarChartTime().setVisible(true);
}
}
The answer does not come from thinking outside the box, rather the answer comes from realizing the truth; There is no Box. my js site
Actually, TooltipChartPanel was something I posted in this thread
http://www.jfree.org/phpBB2/viewtopic.p ... 2&start=45
It is not required for this demo.
Replace
with
and it should work.
http://www.jfree.org/phpBB2/viewtopic.p ... 2&start=45
It is not required for this demo.
Replace
Code: Select all
ChartPanel chartPanel = new TooltipChartPanel(chart);
Code: Select all
CharttPanel chartPanel = new ChartPanel(chart);
The answer does not come from thinking outside the box, rather the answer comes from realizing the truth; There is no Box. my js site
Re: example of Bar Chart(between value and time)?
Dear Experts,
I have short question related to below listed example. When you add second series which values are lower than first series, it hides lower values series by XYBarRenderer, therefore it cannot be seen on the chart. For example:
TimeSeries s2 = new TimeSeries("Series 2", Month.class);
s2.add(new Month(1, 2001), 112);
s2.add(new Month(2, 2001), 11);
s2.add(new Month(3, 2001), 17);
s2.add(new Month(4, 2001), 13);
s2.add(new Month(5, 2001), 17);
s2.add(new Month(6, 2001), 18);
s2.add(new Month(7, 2001), 18);
s2.add(new Month(8, 2001), 13);
s2.add(new Month(9, 2001), 12);
s2.add(new Month(10, 2001), 13);
s2.add(new Month(11, 2001), 11);
s2.add(new Month(12, 2001), 19);
dataset.addSeries(s1);
dataset.addSeries(s2);
// dataset.addSeries(s1);
s1 covers s2 values. If you change order first s2 then s1, i can be seen. Why and do you know any workaround?
Briefly, I have one table which includes Date(TIMESTAMP), X (double), Y(double), Z(double) data. Based on Date(Daily, Monthly, Yearly), I try to plot different type of charts. Such as, Bar chart, Pie chart, ... so on. TimeSeriesCollection samples have mostly line plot. Do you have any suggestions?
Thank you in advance.
Regards,
I have short question related to below listed example. When you add second series which values are lower than first series, it hides lower values series by XYBarRenderer, therefore it cannot be seen on the chart. For example:
TimeSeries s2 = new TimeSeries("Series 2", Month.class);
s2.add(new Month(1, 2001), 112);
s2.add(new Month(2, 2001), 11);
s2.add(new Month(3, 2001), 17);
s2.add(new Month(4, 2001), 13);
s2.add(new Month(5, 2001), 17);
s2.add(new Month(6, 2001), 18);
s2.add(new Month(7, 2001), 18);
s2.add(new Month(8, 2001), 13);
s2.add(new Month(9, 2001), 12);
s2.add(new Month(10, 2001), 13);
s2.add(new Month(11, 2001), 11);
s2.add(new Month(12, 2001), 19);
dataset.addSeries(s1);
dataset.addSeries(s2);
// dataset.addSeries(s1);
s1 covers s2 values. If you change order first s2 then s1, i can be seen. Why and do you know any workaround?
Briefly, I have one table which includes Date(TIMESTAMP), X (double), Y(double), Z(double) data. Based on Date(Daily, Monthly, Yearly), I try to plot different type of charts. Such as, Bar chart, Pie chart, ... so on. TimeSeriesCollection samples have mostly line plot. Do you have any suggestions?
Thank you in advance.
Regards,
Re: example of Bar Chart(between value and time)?
RTJava, I am on the same situation, S2 covers S1... did you finally got the solution to show the 2 series fine?
Thanks.
Thanks.