missing marks on bars with Transparent color

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
Jonathan
Newbie
Newbie
Posts: 60
Joined: Tue Mar 11, 2008 12:00 am
Location: Austin

missing marks on bars with Transparent color

Post by Jonathan » Mon Apr 19, 2010 9:50 pm

Hi,

In the following code, I created a simple histogram chart with displaying total counts of 2 barSeries. If you run the code below, you will see that there are orange colors slightly on the top of the 2nd and 4th bars. This could misinform that there are data for series1 on 2nd and 4th bars. If I set the variable 'hasValue' false in my code below and run it, then I don't see the orange colors on them any more. However, there are 2 missing labels on the 2nd and 4th bars.

Here is my question. How can I display all labels on the top of the bars without displaying colors for 0 data? Note that I don't want to display a label when the total count is 0.

Code: Select all

	public static void main(String[] args) {
		JFrame frame = new JFrame();
		JPanel panel = new JPanel();
		panel.setSize(600, 600);
		TChart chart = new TChart();
		
		panel.add(chart);
		Bar b = new Bar(chart.getChart());
		b.add(1.0, 10.0);
		b.add(2.0, 20.0);
		b.add(3.0, 30.0);
		b.add(4.0, 40.0);
		b.add(5.0, 0.0);
		b.setMultiBar(MultiBars.STACKED);
		b.setBarWidthPercent(100);
		b.getMarks().setVisible(false);
		
		boolean hasValue = true;
		Bar b1 = new Bar(chart.getChart());
		b1.add(1.0, 10.0);
		if(hasValue){
			b1.add(2.0, 0);
		}else{
			b1.add(2.0, 0, Color.TRANSPARENT);
		}
		b1.add(3.0, 30.0);
		if(hasValue){
			b1.add(4.0, 0);
		}else{
			b1.add(4.0, 0, Color.TRANSPARENT);
		}
		b1.add(5.0, 50.0);
		b1.setMultiBar(MultiBars.STACKED);
		b1.setBarWidthPercent(100);
		
		int[] totalMarkCount = new int[b1.getCount()];
		for(int i=0; i<b.getCount(); i++){
			totalMarkCount[i] += b.getMarkValue(i); 
		}

		for(int i=0; i<b1.getCount(); i++){
			totalMarkCount[i] += b1.getMarkValue(i); 
		}

		for(int i=0; i<totalMarkCount.length; i++){
			System.out.println("total count: " + totalMarkCount[i]);
		}

		//move int to StringList
		StringList labelList = new StringList(b1.getCount());
		for(int i=0; i<b1.getCount(); i++){
			labelList.add(i, Integer.toString(totalMarkCount[i]));
		}
		
		//reset new total count to b1
		b1.setLabels(labelList);

		chart.getAxes().getBottom().getLabels().setStyle(AxisLabelStyle.VALUE);

		//set 2D
		chart.getAspect().setView3D(false);
	
		frame.add(panel);
		frame.setSize(600, 600);
		frame.setVisible(true);
}

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: missing marks on bars with Transparent color

Post by Yeray » Wed Apr 21, 2010 11:33 am

Hi Jonathan,

This is the same problem we noticed some time ago in the .NET version here.
I've added it to the defect list to be fixed in future releases (TJ71014824).

I'm afraid that the only workaround I can think on would be using annotation tools to draw your marks yourself.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Jonathan
Newbie
Newbie
Posts: 60
Joined: Tue Mar 11, 2008 12:00 am
Location: Austin

Re: missing marks on bars with Transparent color

Post by Jonathan » Wed Apr 21, 2010 9:18 pm

FYI..

If I add the following code at the end of my code above, it works perfectly.

Code: Select all

		int[] flag = new int[b.getCount()];
		for(int i=0; i<flag.length; i++){
			flag[i] = 0;
		}
		
        for (int i = chart.getSeries().size()-1; i >= 0 ; i--)
        {
            for (int j = 0; j < chart.getSeries(i).getCount(); j++)
            {
                if (chart.getSeries(i).getMarkValue(j) == 0 || flag[j]==1)
                {
                	chart.getSeries(i).getMarks().getItems().getItem(j).setVisible(false);
                	if(chart.getSeries(i).getMarkValue(j) == 0)
                		chart.getSeries(i).setNull(j);	
                }else{
                	flag[j] = 1;
                }
            }
        }

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: missing marks on bars with Transparent color

Post by Yeray » Thu Apr 22, 2010 2:16 pm

Hi Jonathan,

Okay. I'm glad to see you've found a way to work around it!
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply