real-time update of Comination Plots

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Btahlor

real-time update of Comination Plots

Post by Btahlor » Wed Oct 02, 2002 1:50 am

Hi,

I am writing a very complex real-time financial applet and I am using your graphs in combination with Java swing as the center piece of the applet. I am very impressed with the simplicity of your design and the vast amount of samples.

However, I have been using simple single XYplots up to now and I have been updating the data with the following:

// convert to proper dataset
HighLowDataset data1 = createHiLoDataY(days,allData,symbol);

// Update plot with new data
chartC.getPlot().setDataset(data1);

I am now trying to work with Combination charts (price on top, Volume on the bottom), I am able to create the plot as per your sample code(JFreeChartDemoBase.java) but I can not seem to be able to force an update of the plot with new data as I did with simple XYplots.


any suggestions ???


Barry


.

btahlor

Changing Data on Combined Charts

Post by btahlor » Fri Oct 04, 2002 6:51 am

HI,

I am having the hardest time changing the data in a Combined plot.

The following code below (grabbed from the Demo code) is what I used to create the Combined chart. It plots perfectly, but I want to change the entire dataset based on a user selection for different ranges (60 day, 90, 180 ... 5 years).

How do I get to the data for each subplot and change the entire dataset ? I know how to get to the data and change it with NON combined charts!!!


-------------------------------------------------------

// more setup code

// create data1 from a URL file
XYDataset data1 = createHiLoDataY(90days,allData,"don.prn");
XYDataset dataV = createVolumeDataset();

// create master Dataset
CombinedDataset data = new CombinedDataset();

data.add(data1); // time series
data.add(dataV); // volume data

// test XYSubDataset and CombinedDataset operations

// decompose data into its two dataset series
XYDataset series0 = new SubSeriesDataset(data, 0);
XYDataset series1 = new SubSeriesDataset(data, 1);

int n = 2; // number of combined (vertically laidout) charts

// make one vertical axis for each (vertical) chart
NumberAxis[] valueAxis = new NumberAxis[2];
for (int i=0; i<valueAxis.length; i++) {
valueAxis = new VerticalNumberAxis(ranges);
valueAxis.setCrosshairVisible(true);
if (i <= 1) {
valueAxis.setAutoRangeIncludesZero(false); // override default
}
}

// create CombinedPlot...
CombinedXYPlot multiPlot = new CombinedXYPlot(new HorizontalDateAxis(domain), CombinedXYPlot.VERTICAL);

int[] weight = { 3, 1 };

// add subplot1...
XYPlot subplot1 = new XYPlot(series0, null, new VerticalNumberAxis(ranges[0]));
NumberAxis axis1 = (NumberAxis)subplot1.getRangeAxis();
axis1.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7));
axis1.setLabelFont(new Font("SansSerif", Font.PLAIN, 8));
axis1.setAutoRangeIncludesZero(false);
multiPlot.add(subplot1, weight[0]);

// add subplot2...
XYPlot subplot2 = new XYPlot(series1, null, new VerticalNumberAxis(ranges[1]));
NumberAxis axis2 = (NumberAxis)subplot2.getRangeAxis();
axis2.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7));
axis2.setLabelFont(new Font("SansSerif", Font.PLAIN, 8));
axis2.setAutoRangeIncludesZero(false);
multiPlot.add(subplot2, weight[1]);


// now create the master JFreeChart object
JFreeChart chart = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 12), multiPlot, true);

// then customise it a little...
TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 10));
chart.addTitle(subtitle);
chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white,0, 1000, Color.blue));
return chart;
--------------------------------------------------------------
any guidance is appreciated


Barry

David Gilbert

Re: real-time update of Comination Plots

Post by David Gilbert » Fri Oct 04, 2002 5:02 pm

Hi Barry,

I think you want to try to hold onto references to either:

(1) the datasets, so you can change their contents (and the chart should update automatically); or

(2) the subplots, so you can replace the datasets (and again the chart should update automatically).

If you only have a reference to the chart, then you will have a hard time recursing down the structure to get the datasets for all the subplots.

Regards,

DG

Locked