Ignore Zero values in XY line Chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
atom007
Posts: 9
Joined: Tue Jun 25, 2013 7:56 pm
antibot: No, of course not.

Ignore Zero values in XY line Chart

Post by atom007 » Tue Jun 25, 2013 8:02 pm

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 ?

atom007
Posts: 9
Joined: Tue Jun 25, 2013 7:56 pm
antibot: No, of course not.

Re: Ignore Zero values in XY line Chart

Post by atom007 » Wed Jun 26, 2013 3:51 am

Can someone help me plz? :)

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Ignore Zero values in XY line Chart

Post by John Matthews » Wed Jun 26, 2013 4:34 am

Cross-posted here.

atom007
Posts: 9
Joined: Tue Jun 25, 2013 7:56 pm
antibot: No, of course not.

Re: Ignore Zero values in XY line Chart

Post by atom007 » Wed Jun 26, 2013 6:01 am

@John : any wrong in cross posting..I was not aware!.

atom007
Posts: 9
Joined: Tue Jun 25, 2013 7:56 pm
antibot: No, of course not.

Re: Ignore Zero values in XY line Chart

Post by atom007 » Wed Jun 26, 2013 11:02 am

Any Suggestions please?

atom007
Posts: 9
Joined: Tue Jun 25, 2013 7:56 pm
antibot: No, of course not.

Re: Ignore Zero values in XY line Chart

Post by atom007 » Wed Jun 26, 2013 1:33 pm

@David : can you suggest please?

remiohead
Posts: 201
Joined: Fri Oct 02, 2009 3:53 pm
antibot: No, of course not.

Re: Ignore Zero values in XY line Chart

Post by remiohead » Wed Jun 26, 2013 2:20 pm

Do not add the point to the dataset if the values are zero?

atom007
Posts: 9
Joined: Tue Jun 25, 2013 7:56 pm
antibot: No, of course not.

Re: Ignore Zero values in XY line Chart

Post by atom007 » Wed Jun 26, 2013 6:16 pm

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?

remiohead
Posts: 201
Joined: Fri Oct 02, 2009 3:53 pm
antibot: No, of course not.

Re: Ignore Zero values in XY line Chart

Post by remiohead » Wed Jun 26, 2013 8:48 pm

Write your own renderer (or extend XYLineAndShapeRenderer) to do what you want. There is no built in way to ignore zero.

atom007
Posts: 9
Joined: Tue Jun 25, 2013 7:56 pm
antibot: No, of course not.

Re: Ignore Zero values in XY line Chart

Post by atom007 » Thu Jun 27, 2013 6:32 am

Any samples how to do that?

remiohead
Posts: 201
Joined: Fri Oct 02, 2009 3:53 pm
antibot: No, of course not.

Re: Ignore Zero values in XY line Chart

Post by remiohead » Thu Jun 27, 2013 12:53 pm

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.

david.gilbert
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

Post by david.gilbert » Tue Jul 02, 2013 10:36 am

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)?
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

atom007
Posts: 9
Joined: Tue Jun 25, 2013 7:56 pm
antibot: No, of course not.

Re: Ignore Zero values in XY line Chart

Post by atom007 » Tue Jul 02, 2013 12:24 pm

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.

Locked