Any JFreeChart users? Having trouble with multiple axes

D

Danger_Duck

I posted this in their forum, but I know this one has a MUCH faster
response. I DO feel kinda guilty about this cross-post, so is there
any way to notify crosspost/linking etc.?

Anyway, here's my question. I'm using the latest version: 1.0.10

"Say I want to graph two functions on the same chart to see
correlation. The problem is, one of the units is in mm while the other
is in m. Obviously, this is a case where I would like two y-axes so
the mm series isn't dwarfed by the m series.

Well, I start by doing something like this:

public void displayChart(xVariable[] vars) {
XYSeriesCollection[] data = new XYSeriesCollection[vars.length];
NumberAxis[] varAxes = new NumberAxis[vars.length];

for (int k = 0; k < vars.length; k++) {
varAxes[k] = new NumberAxis(vars[k].getName());

XYSeries in = new XYSeries(vars[k].getName());
//(I added each (x,y) value here, omitted for brevity)
data[k].addSeries(in);
}

JFreeChart graph = ChartFactory.createXYLineChart(
"Values for variables in " + testName, "Indice", testName + "
Variables", data[0],
PlotOrientation.VERTICAL, true, true, false);
graph.getCategoryPlot().setRangeAxes(varAxes);

for (int i = 0; i < vars.length; i++)
graph.getCategoryPlot().setDataset(i, data);


Well, at compile-time, I see that the ".setDataset()" method expects a
category plot and apparently the XYSeriesCollection is no such thing.

So, I tried XYDataSet instead, but this did not have the .addSeries()
method, and it too was not a Category Plot.

So, how exactly do I add multiple y-axes to a single chart? Any help
would be appreciated."
 
D

Danger_Duck

I posted this in their forum, but I know this one has a MUCH faster
response. I DO feel kinda guilty about this cross-post, so is there
any way to notify crosspost/linking etc.?

Anyway, here's my question. I'm using the latest version: 1.0.10

"Say I want to graph two functions on the same chart to see
correlation. The problem is, one of the units is in mm while the other
is in m. Obviously, this is a case where I would like two y-axes so
the mm series isn't dwarfed by the m series.

Well, I start by doing something like this:

public void displayChart(xVariable[] vars) {
XYSeriesCollection[] data = new XYSeriesCollection[vars.length];
NumberAxis[] varAxes = new NumberAxis[vars.length];

for (int k = 0; k < vars.length; k++) {
varAxes[k] = new NumberAxis(vars[k].getName());

XYSeries in = new XYSeries(vars[k].getName());
//(I added each (x,y) value here, omitted for brevity)
data[k].addSeries(in);

}

JFreeChart graph = ChartFactory.createXYLineChart(
"Values for variables in " + testName, "Indice", testName + "
Variables", data[0],
PlotOrientation.VERTICAL, true, true, false);
graph.getCategoryPlot().setRangeAxes(varAxes);

for (int i = 0; i < vars.length; i++)
graph.getCategoryPlot().setDataset(i, data);

Well, at compile-time, I see that the ".setDataset()" method expects a
category plot and apparently the XYSeriesCollection is no such thing.

So, I tried XYDataSet instead, but this did not have the .addSeries()
method, and it too was not a Category Plot.

So, how exactly do I add multiple y-axes to a single chart? Any help
would be appreciated."


Is there any way to like, delete posts?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top