Page 1 of 1

Stacked Bar Chart in android

Posted: Tue Jan 24, 2012 10:01 am
by 17060683
Hello,
Is it possible to show a bar chart like in attached image?

Regards
Shibu
Indus Systems

Re: Stacked Bar Chart in android

Posted: Tue Jan 24, 2012 11:47 am
by yeray
Hi Shibu,

The following code draws a chart very similar to the chart in your picture for me here.
There was actually a problem with the marks when they are set to be drawn in the center for stacked bars (TJ71015973). I've just fixed it for the next versions.

Code: Select all

		tChart1.getAspect().setView3D(false);
		
		tChart1.getPanel().setColor(Color.black);
		tChart1.getWalls().setVisible(false);
		tChart1.getAxes().getLeft().getLabels().getFont().setColor(Color.white);
		tChart1.getAxes().getBottom().getLabels().getFont().setColor(Color.white);
		tChart1.getHeader().getFont().setColor(Color.white);
		tChart1.getHeader().getFont().setSize(15);
		tChart1.getHeader().setText("Dallas | Building 1 | Floor 1");
		tChart1.getHeader().setAlignment(StringAlignment.NEAR);
		tChart1.getLegend().setAlignment(LegendAlignment.BOTTOM);
		tChart1.getLegend().getFont().setColor(Color.white);
		tChart1.getLegend().setTransparent(true);
		tChart1.getAxes().getLeft().setIncrement(50);
		tChart1.getAxes().getLeft().setMinMax(0, 350);
		tChart1.getAxes().getBottom().getGrid().setVisible(false);
		
		for (int i=0; i<2; i++) {
			Bar bar = new Bar(tChart1.getChart());
			bar.setMultiBar(MultiBars.STACKED);
			bar.setMarksOnBar(true);
			bar.setMarksLocation(MarksLocation.Center);
			bar.getMarks().setStyle(MarksStyle.VALUE);
			bar.getMarks().setTransparent(true);
			bar.getMarks().getFont().setColor(Color.white);
			bar.getMarks().getFont().setSize(13);
		}
		
		Bar bar1 = (Bar)(tChart1.getSeries(0));
		bar1.setTitle("Occupied");
		bar1.add(250, "Administration");
		bar1.add(145, "Human Resource");
		bar1.add(60, "Finance");
		bar1.add(275, "Support");
		
		Bar bar2 = (Bar)(tChart1.getSeries(1));
		bar2.setTitle("Vacant");
		bar2.setColor(Color.fromArgb(220,80,80));
		bar2.add(50);
		bar2.add(10);
		bar2.add(20);
		bar2.add(25);
Bars.png
Bars.png (20.35 KiB) Viewed 11181 times

Re: Stacked Bar Chart in android

Posted: Wed Jan 25, 2012 4:58 am
by 17060683
Hello, Yeray Alonso

Thank you for your support

Shibu
Indus Systems Inc