Page 1 of 1

Hide Zero Values

Posted: Fri Feb 24, 2012 11:22 am
by 17060683
Hello,

We are planning to remove zero values fromn tha chart. see the grid and chart in attached image. Right now alignment is not proper and X values for some series are not showing.

Is there any way to hide zero values from chart?


Regards
Shibu
Indus Systems Inc

Re: Hide Zero Values

Posted: Tue Feb 28, 2012 3:32 pm
by yeray
Hi Shibu,

I'm trying to reproduce the situation with the code below:

Code: Select all

		ThemesList.applyTheme(tChart1.getChart(), 1);
		
		tChart1.getAspect().setView3D(false);
		
		Bar occupi = new Bar(tChart1.getChart());
		Bar vacant = new Bar(tChart1.getChart());
		
		occupi.setColor(Color.BLUE);
		vacant.setColor(Color.RED.applyDark(20));
		
		occupi.add(2);
		occupi.add(1);
		occupi.add(3);
		occupi.add(0);
		
		vacant.add(5);
		vacant.add(0);
		vacant.add(9);
		vacant.add(3);
But it seems to give me the expected result:
device-2012-02-28-161732.png
TeeChart Java for Android v3.2012.0202
device-2012-02-28-161732.png (10.85 KiB) Viewed 13554 times
If that's not what you want, could you please try to explain how do you exactly want the 0 values to be drawn?

Re: Hide Zero Values

Posted: Wed Feb 29, 2012 7:25 am
by 17060683
Hello, Yeray
Actually, We have to hide zero from the chart and that we got. But right now that series values with zero showing as empty in chart. As we have lot of series in this chart and there may exists only some item with zero values but it could be different for each category.

For e.g.
Series 1 has 1, 5, 0, 4, 0, 8, 3, 0
Series 2 has 0, 3, 1, 0, 2, 0, 3, 8
....
.....

While we are creating chart using addNull for zero values our previous problem was solved. but it take space for that series in each category. If we can trim that space, it can avoid more horizontal panning in chart

See attachment for more


Regards
Shibu
Indus Systems Inc

Re: Hide Zero Values

Posted: Mon Mar 05, 2012 5:04 pm
by yeray
Hi Shibu,

Excuse us for the delayed reply.
TeeChart doesn't handle the null points in any way, it just doesn't draw them. If I understand well, you'd like to handle two different situations that can be explained with this snipped of code:

Code: Select all

		tChart1.getAspect().setView3D(false);
		
		for (int i=0; i<3; i++) {
			Bar b = new Bar(tChart1.getChart());
			b.fillSampleValues();
			b.setNull(2);
			if (i>0) b.setNull(3);
			if (i>1) b.setNull(4);
		}
This is what I get as is:
null bars.png
null bars.png (33.7 KiB) Viewed 13435 times
So, the two situations to handle would be:
1. When no series have a visible value for a ValueIndex. In the example above, this happens at ValueIndex 2. You could use an Axis Break tool every time you detect this situation.
2. When there is at least one visible point for a ValueIndex, and at least one not visible: This happens in the example above at ValueIndex 3 and 4. Here, you should calculate the new position and size of the bars manually.

Here you have a first (incomplete) approximation:

Code: Select all

		int maxCount = 0;
		for (int nSeries=0; nSeries<tChart1.getSeriesCount(); nSeries++) {
			maxCount = Math.max(maxCount, tChart1.getSeries(nSeries).getCount());
		}
		
		axisBreaksTool = new AxisBreaksTool(tChart1.getChart().getAxes().getBottom());
		axisBreaksTool.setAxis(tChart1.getAxes().getBottom());
        
		tChart1.getAxes().getBottom().getLabels().getItems().clear();
		for (int valueIndex=0; valueIndex<maxCount; valueIndex++) {
			int nVisible = 0;
			for (int nSeries=0; nSeries<tChart1.getSeriesCount(); nSeries++) {
				if (!tChart1.getSeries(nSeries).isNull(valueIndex))
					nVisible++;
			}
			if (nVisible>0) {
				double val = tChart1.getSeries(0).getXValues().getValue(valueIndex);
				tChart1.getAxes().getBottom().getLabels().getItems().add(val, formatValue(val));
				for (int nSeries=0; nSeries<tChart1.getSeriesCount(); nSeries++) {
					if (!tChart1.getSeries(nSeries).isNull(valueIndex))
					{
						//Recalculate bar width and position
					}
				}
			}
			else {
				double val = tChart1.getSeries(0).getXValues().getValue(valueIndex);
				AxisBreak aBreak = new AxisBreak(axisBreaksTool);
				aBreak.setEndValue(val+0.5);
				aBreak.setStartValue(val-0.5);
				aBreak.setStyle(AxisBreakStyle.NONE);
				axisBreaksTool.getBreaks().add(aBreak);
			}
		}
Notes:
Take a look at the BarSizeDemo in the features demo program to see how the bars could be moved along the horizontal axis.
You could use the setCustomBarWidth function to set the recalculated bar sizes.