I am evaluating the JFreeChart(never used JFreeChart before). I would like to create a chart while the x-axis with values(3month, 6 months, 1 year, 2 year, 5 year, 10 year and 30 year) and there will at least two sets of values(say yield for US, for Canada and...) for the y-axis.
Is this feasible? How should I do it? Do you have any sample code?
Thanks for the help in advance.
my e-mail address: helen.lin@tdsecurities.com
create a chart with not-fixed length of time fragments and .
is no big deal ... in fact it's very straightforward:
i hope this helps ...
regards[/code]
Code: Select all
JFreeChart chart;
//JFreeChart datasets
public TimeSeriesCollection xyseries=new TimeSeriesCollection(); // XYSeriesCollection (see ttp://www.jfree.org/jfreechart/javadoc/org/jfree/data/XYSeriesCollection.html)
TimeSeries x1;
TimeSeries bollinger_top;
TimeSeries bollinger_bottom;
TimeSeries average1;
TimeSeries average2;
ChartPanel chartPanel;
//-........
x1=new TimeSeries("symbol", FixedMillisecond.class);
average1=new TimeSeries("av1", FixedMillisecond.class);
xyseries.addSeries(x1);
xyseries.addSeries(average1);
System.out.println("Populated.");
//
JFreeChart chart = createChart(xyseries);
System.out.println("constr.");
chart.getXYPlot().setOrientation(PlotOrientation.VERTICAL);
chart.setAntiAlias(false);
chart.setBackgroundPaint(new Color(255,255,255));
chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
//...............
public void calcAverage1(int d, Date timestamp){
try{
double v=0;
List l1=x1.getItems();
for(int i=d;i<d+av1;i++){
v+=x1.getValue(x1.getItemCount()-(av1-i)).doubleValue();
}
average1.add(new FixedMillisecond(timestamp), v/av1);
}
catch(Exception e){
//e.printStackTrace();
//System.out.println(timestamp.toString());
}
}
regards[/code]