Ignore Zero values in XY line Chart
Ignore Zero values in XY line Chart
Hiya,
I have a XY Line chart wherein i doesnt want to show the value zero eventhough the graph is plotted at the below i.e just ignorezerovalues as in stackedbar chart which works pretty good.
Any suggestions ?
I have a XY Line chart wherein i doesnt want to show the value zero eventhough the graph is plotted at the below i.e just ignorezerovalues as in stackedbar chart which works pretty good.
Any suggestions ?
Re: Ignore Zero values in XY line Chart
Can someone help me plz?
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Ignore Zero values in XY line Chart
Cross-posted here.
Re: Ignore Zero values in XY line Chart
@John : any wrong in cross posting..I was not aware!.
Re: Ignore Zero values in XY line Chart
Any Suggestions please?
Re: Ignore Zero values in XY line Chart
@David : can you suggest please?
Re: Ignore Zero values in XY line Chart
Do not add the point to the dataset if the values are zero?
Re: Ignore Zero values in XY line Chart
Hi,
At first thanks for your reply.
If i don't add points to dataset if it is ZERO ,there will not be a plot(line) at that particular.
In my case i just need to ignore the zero but plot .any ideas?
At first thanks for your reply.
If i don't add points to dataset if it is ZERO ,there will not be a plot(line) at that particular.
In my case i just need to ignore the zero but plot .any ideas?
Re: Ignore Zero values in XY line Chart
Write your own renderer (or extend XYLineAndShapeRenderer) to do what you want. There is no built in way to ignore zero.
Re: Ignore Zero values in XY line Chart
Any samples how to do that?
Re: Ignore Zero values in XY line Chart
You are a programmer right? The JFree source code is one large sample. Take XYLineAndShapeRenderer as your base, learn how it works, figure out which methods need to be modified and then do it.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: Ignore Zero values in XY line Chart
It's not 100% clear to me what you want. Is it just that you don't want zero to be displayed in the axis tick labels? In that case, you would need to override the refreshTicks() method in the NumberAxis class to ensure that no tick label is generated for zero.
If it is something else, can you explain it further (a mock-up of what you are trying to achieve would be good)?
If it is something else, can you explain it further (a mock-up of what you are trying to achieve would be good)?
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
Re: Ignore Zero values in XY line Chart
Hi David,
thanks for the reply.
I have successfully created the XY Line chart where i just don't want to display the zeroes in the plot i.e if i have 3 values say (5.0,0.0,3.0) , the output should be plotted but DO NOT show the value zero like you gave an option in stackedbar (setIgnoreZeroValues()) .
To be very clear while generating BaseItemLabels just show values other than ZERO.
let me show you what i tried..
double values[] = {0.0, 33.0, 44.0, 0.0, 0.0}; //show only 33,44 but plot all values.
XYSeries series1 = new XYSeries("Alpha", false);
for (int i = 0; i < values.length; i++) {
series1.add(values, i);
}
double values[] = {11.0, 3.0, 14.0, 70.0, 0.0}; //plot all values and show only 11,3,14,70
XYSeries series2 = new XYSeries("Alpha1", false);
for (int i = 0; i < values.length; i++) {
serie21.add(values, i);
}
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series1);
dataset.addSeries(series2);
JFreeChart chart = ChartFactory.createXYLineChart("Title", "Values",
"", dataset, PlotOrientation.HORIZONTAL, true, true, false);
XYPlot plot = (XYPlot) chart.getPlot();
String[] Alp= {"A", "B", "C", "D", "E"};
SymbolAxis rangeAxis = new SymbolAxis("Alphabets", Alp);
plot.setRangeAxis(rangeAxis);
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
renderer.setBaseShapesVisible(true);
renderer.setBaseSeriesVisible(true);
XYItemLabelGenerator generator = new StandardXYItemLabelGenerator("{1}", new DecimalFormat("0"), new DecimalFormat("0.00%"));
renderer.setBaseItemLabelGenerator(generator);
renderer.setBaseItemLabelsVisible(true);
//Remaining is just setting theme...
I tried changing the values in generator format but nothing worked.
Please suggest me and hope i have made the question clear..
Thanks in advance.
thanks for the reply.
I have successfully created the XY Line chart where i just don't want to display the zeroes in the plot i.e if i have 3 values say (5.0,0.0,3.0) , the output should be plotted but DO NOT show the value zero like you gave an option in stackedbar (setIgnoreZeroValues()) .
To be very clear while generating BaseItemLabels just show values other than ZERO.
let me show you what i tried..
double values[] = {0.0, 33.0, 44.0, 0.0, 0.0}; //show only 33,44 but plot all values.
XYSeries series1 = new XYSeries("Alpha", false);
for (int i = 0; i < values.length; i++) {
series1.add(values, i);
}
double values[] = {11.0, 3.0, 14.0, 70.0, 0.0}; //plot all values and show only 11,3,14,70
XYSeries series2 = new XYSeries("Alpha1", false);
for (int i = 0; i < values.length; i++) {
serie21.add(values, i);
}
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series1);
dataset.addSeries(series2);
JFreeChart chart = ChartFactory.createXYLineChart("Title", "Values",
"", dataset, PlotOrientation.HORIZONTAL, true, true, false);
XYPlot plot = (XYPlot) chart.getPlot();
String[] Alp= {"A", "B", "C", "D", "E"};
SymbolAxis rangeAxis = new SymbolAxis("Alphabets", Alp);
plot.setRangeAxis(rangeAxis);
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
renderer.setBaseShapesVisible(true);
renderer.setBaseSeriesVisible(true);
XYItemLabelGenerator generator = new StandardXYItemLabelGenerator("{1}", new DecimalFormat("0"), new DecimalFormat("0.00%"));
renderer.setBaseItemLabelGenerator(generator);
renderer.setBaseItemLabelsVisible(true);
//Remaining is just setting theme...
I tried changing the values in generator format but nothing worked.
Please suggest me and hope i have made the question clear..
Thanks in advance.