Page 1 of 1

missing marks on bars with Transparent color

Posted: Mon Apr 19, 2010 9:50 pm
by 7667590
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);
}

Re: missing marks on bars with Transparent color

Posted: Wed Apr 21, 2010 11:33 am
by yeray
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.

Re: missing marks on bars with Transparent color

Posted: Wed Apr 21, 2010 9:18 pm
by 7667590
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;
                }
            }
        }

Re: missing marks on bars with Transparent color

Posted: Thu Apr 22, 2010 2:16 pm
by yeray
Hi Jonathan,

Okay. I'm glad to see you've found a way to work around it!