A discussion forum for JFreeChart (a 2D chart library for the Java platform).
-
Birgi
- Posts: 21
- Joined: Mon Mar 14, 2005 9:09 pm
Post
by Birgi » Mon Mar 21, 2005 10:57 am
Hi Everybody.
I am trying to make a multiple axis chart. I have the following code,
Code: Select all
chart = ChartFactory.createBarChart(
criteria + " Grafiği",// chart title
"Ürünler",// domain axis label
criteria,// range axis label
dataset,// data
PlotOrientation.VERTICAL,
false,// include legend
true,// tooltips?
false// URLS?
);
chart.setBackgroundPaint(Color.lightGray);
// creating the secondary chart & secondary axis
CategoryPlot plot = chart.getCategoryPlot();
NumberAxis axis2 = new NumberAxis("Satış Yüzdesi");
plot.setSecondaryRangeAxis(0, axis2);...
Without the "creating the secondary chart&axis" part it perfectly creates a bar chart. Now I want to make a line chart on it and when i compile this code it gives the following error;
C:\My Documents\OdesaProject\OdesaProject\ChartCreator.java:103: cannot resolve symbol
symbol : method setSecondaryRangeAxis (int,org.jfree.chart.axis.NumberAxis)
location: class org.jfree.chart.plot.CategoryPlot
plot.setSecondaryRangeAxis(0, axis2);
Can you please help?
Thanks
Birgi
-
Birgi
- Posts: 21
- Joined: Mon Mar 14, 2005 9:09 pm
Post
by Birgi » Mon Mar 21, 2005 11:01 pm
I also have another problem...
I have to get the CategoryItemEntity at a point of a ChartPanel. The method .getEntityForPoint(int,int) returns a ChartEntity object.
Can anybody suggest me a way of doing one of these;
1- Directly getting the CategoryItemEntity form the ChartPanel
2- Converting that ChartEntity item into a CategoryItemEntity...
Thanks
Birgi
-
Alex Manoylenko
- Posts: 18
- Joined: Fri Mar 11, 2005 9:41 pm
- Location: Ukraine
-
Contact:
Post
by Alex Manoylenko » Tue Mar 22, 2005 2:30 pm
Hello, Birgi.
Your first problem coinsides with my problem showed in "Help please" topic. Do you resolve it?
Thanks a lot.
Bets regards, Alex
-
Birgi
- Posts: 21
- Joined: Mon Mar 14, 2005 9:09 pm
Post
by Birgi » Tue Mar 22, 2005 4:13 pm
Hi Alex,
Unfortunately I could not do it. And you are right, I also need a bar chart with a line chart on it... I looked at some examples. They all have a code starting like this for the multiple axis charts;
Code: Select all
plot.setSecondaryRangeAxis(0, axis2);
... ... ...
However I looked at the documentation and could not find such method in any of the plot classes.
I hope someone helps soon.
Birgi
-
Alex Manoylenko
- Posts: 18
- Joined: Fri Mar 11, 2005 9:41 pm
- Location: Ukraine
-
Contact:
Post
by Alex Manoylenko » Tue Mar 22, 2005 4:21 pm
Thanks Birgi for your answering.
Anybody wants to help us
But I hope somebody helps us :^)
My ICQ: 279533452.
Write please, if you find how to resolve this issue.
Thanks a lot.
Best regards, Alex
-
david.gilbert
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
-
Contact:
Post
by david.gilbert » Tue Mar 22, 2005 4:24 pm
There used to be separate methods for setting the "secondary" axes, but they were unnecessary. Now you just use setRangeAxis(int, ValueAxis) where the int argument specifies which axis you are adding.
Make sure you have the latest version of JFreeChart, the developer guide and the demo apps. Or if you prefer working with an older version, make sure you have versions that are consistent with one another, as the API has changed from release to release (soon a stable 1.0.0 release will be made).
-
Birgi
- Posts: 21
- Joined: Mon Mar 14, 2005 9:09 pm
Post
by Birgi » Tue Mar 22, 2005 5:44 pm
David,
Thanks alot. My second axis appeared, but now I donot see a line chart.
I have the following code;
Code: Select all
CategoryPlot plot = chart.getCategoryPlot();
NumberAxis axis2 = new NumberAxis("Satış Yüzdesi");
plot.setRangeAxis(1, axis2);
plot.setDataset(1, secondaryDataset);
To see a line chart with the secondaryDateset what else do I have to do?
Thanks for your help
Birgi
-
david.gilbert
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
-
Contact:
Post
by david.gilbert » Tue Mar 22, 2005 5:48 pm
You will need something like this:
Code: Select all
plot.setRenderer(1, new LineAndShapeRenderer(...));
plot.mapDatasetToRangeAxis(1, 1);
-
Birgi
- Posts: 21
- Joined: Mon Mar 14, 2005 9:09 pm
Post
by Birgi » Tue Mar 22, 2005 6:17 pm
David,
Sorry for bothering you this much, but I still have a problem. My code for creating the chart is as follows;
Code: Select all
chart = ChartFactory.createBarChart(
criteria + " Grafiği", // chart title
"Ürünler", // domain axis label
criteria, // range axis label
dataset, // data
PlotOrientation.VERTICAL,
false, // include legend
true, // tooltips?
false // URLS?
);
chart.setBackgroundPaint(Color.lightGray);
// creating the secondary chart & secondary axis
CategoryPlot plot = chart.getCategoryPlot();
NumberAxis axis2 = new NumberAxis("Satış Yüzdesi");
plot.setRangeAxis(1, axis2);
plot.setDataset(1, secondaryDataset);
plot.setRenderer(1, new LineAndShapeRenderer());
plot.mapDatasetToRangeAxis(1, 1);
Now the problem is, shapes for representing data points appear on the chart, but they are all on the same y-axis ( I mean on the same vertical line). I also cannot see any lines ( probably that's because of the data points).
Thanks a lot for your help.
Birgi
-
david.gilbert
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
-
Contact:
Post
by david.gilbert » Tue Mar 22, 2005 6:32 pm
I think this has something to do with the values in your dataset, but since I don't know what they are I can't be sure.
-
Birgi
- Posts: 21
- Joined: Mon Mar 14, 2005 9:09 pm
Post
by Birgi » Tue Mar 22, 2005 7:02 pm
David,
I tried it with a very simle dataset like;
Code: Select all
DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
dataset2.addValue(0.3,"birgi","");
dataset2.addValue(0.95,"damla","");
Now one shape appears on 0.3 and another shape appears on 0.95, but they are still on the same vertical line. [If you want I can try to put a screen shot.]
Thanks
Birgi
-
david.gilbert
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
-
Contact:
Post
by david.gilbert » Tue Mar 22, 2005 7:05 pm
That is because for both values the category is "" (empty string). Try this to see the difference:
Code: Select all
DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
dataset2.addValue(0.3,"birgi","Category 1");
dataset2.addValue(0.95,"damla","Category 2");
You probably want "Category 1" and "Category 2" to match the entries in your other dataset.
-
Birgi
- Posts: 21
- Joined: Mon Mar 14, 2005 9:09 pm
Post
by Birgi » Tue Mar 22, 2005 7:21 pm
David,
Now I can see all the data points. However I cannot see the lines connecting them. I used the method "isLinesVisible()" for the LineAndShapeRenderer object and it returned "true".
My line chart seems to be under the bar chart (I cannot see data points if they are under a bar). Can this be the reason of not seeing the lines?
Thanks
Birgi
-
david.gilbert
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
-
Contact:
Post
by david.gilbert » Tue Mar 22, 2005 7:54 pm
You can change that with the setDatasetRenderingOrder() method in the CategoryPlot class.
-
Birgi
- Posts: 21
- Joined: Mon Mar 14, 2005 9:09 pm
Post
by Birgi » Tue Mar 22, 2005 8:11 pm
David,
Now I can see all the data points, but I still cannot see the lines connecting them. "isLinesVisible()" method still returns "true". However I have the following chart, maybe an image would help;
and my code for this chart is;
Code: Select all
chart = ChartFactory.createBarChart(
criteria + " Grafiği", // chart title
"Ürünler", // domain axis label
criteria, // range axis label
dataset, // data
PlotOrientation.VERTICAL,
false, // include legend
true, // tooltips?
false // URLS?
);
chart.setBackgroundPaint(Color.lightGray);
// creating the secondary chart & secondary axis
CategoryPlot plot = chart.getCategoryPlot();
NumberAxis axis2 = new NumberAxis("Satış Yüzdesi");
plot.setRangeAxis(1, axis2);
plot.setDataset(1, secondaryDataset);
LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(true,true);
plot.setRenderer(1, lineRenderer);
plot.mapDatasetToRangeAxis(1, 1);
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
Thanks a lot
Birgi