Line chart x axis labels repeating

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
Chen
Newbie
Newbie
Posts: 43
Joined: Tue Mar 11, 2008 12:00 am
Contact:

Line chart x axis labels repeating

Post by Chen » Wed Oct 08, 2008 6:26 pm

Hi,

package com.amd.ngeda.chart.teechart;

import javax.swing.JFrame;
import javax.swing.JPanel;

import com.steema.teechart.TChart;
import com.steema.teechart.styles.Line;

public class Test {

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);

// [(1), (3), (10)]
// [(1), (2), (3), (10)]
// [(1), (3)]
// [(1), (2), (3), (4), (7), (8), (9), (10)]
// [(1), (2), (3), (7), (10), (15)]
// [(1), (2), (3), (10)]
// [(1), (2), (3), (10)]
// [(1), (3), (4)]
// [(1), (2), (3), (4), (7), (10)]
// [(1), (2), (3), (4), (7), (8), (10)]
// [(1), (2), (3), (10)]
// [(1), (2), (3), (4), (7), (10)]
// [(1), (2), (3), (4), (10), (15)]
//
//

Line fastLine = new Line(chart.getChart());
fastLine.add(2, ""+1);
fastLine.add(3, ""+3);
fastLine.add(4, ""+10);

Line fastLine11 = new Line(chart.getChart());
fastLine11.add(1, ""+1);
fastLine11.add(3, ""+2);
fastLine11.add(8, ""+3);
fastLine11.add(4, ""+10);

Line fastLine1 = new Line(chart.getChart());
fastLine1.add(10, ""+1);
fastLine1.add(20, ""+3);

Line fastLine4 = new Line(chart.getChart());
fastLine4.add(10, ""+1);
fastLine4.add(20, ""+2);
fastLine4.add(20, ""+3);
fastLine4.add(20, ""+4);
fastLine4.add(20, ""+7);
fastLine4.add(20, ""+8);
fastLine4.add(20, ""+9);
fastLine4.add(20, ""+10);

Line fastLine5 = new Line(chart.getChart());
fastLine5.add(10, ""+1);
fastLine5.add(20, ""+2);
fastLine5.add(20, ""+3);
fastLine5.add(20, ""+10);
fastLine5.add(20, ""+15);

frame.add(panel);
frame.setSize(600, 600);
frame.setVisible(true);
}
}


If you run this code then you will find that x axis contains duplicate labels.
I want to use add(double, String) in my code and I do not want to see duplicate labels. Is this a bug or feature ????? OR AM I DOING SOMETHING WRONG ? Any help would be appreciated.


Thanks,
Varun

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Oct 09, 2008 9:47 am

Hi Varun,

Sorry but I'm not able to reproduce the problem here. Could you please check that your code was correctly pasted and parsed by the forums message editor? I suggest you to surround your code snippets with "code" "/code" tags.

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Chen
Newbie
Newbie
Posts: 43
Joined: Tue Mar 11, 2008 12:00 am
Contact:

Post by Chen » Thu Oct 09, 2008 1:00 pm

Code: Select all

Hi,

package com.amd.ngeda.chart.teechart;

import javax.swing.JFrame;
import javax.swing.JPanel;

import com.steema.teechart.TChart;
import com.steema.teechart.styles.Line;

public class Test {

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);

// [(1), (3), (10)]
// [(1), (2), (3), (10)]
// [(1), (3)]
// [(1), (2), (3), (4), (7), (8), (9), (10)]
// [(1), (2), (3), (7), (10), (15)]
// [(1), (2), (3), (10)]
// [(1), (2), (3), (10)]
// [(1), (3), (4)]
// [(1), (2), (3), (4), (7), (10)]
// [(1), (2), (3), (4), (7), (8), (10)]
// [(1), (2), (3), (10)]
// [(1), (2), (3), (4), (7), (10)]
// [(1), (2), (3), (4), (10), (15)]
//
//

Line fastLine = new Line(chart.getChart());
fastLine.add(2, ""+1);
fastLine.add(3, ""+3);
fastLine.add(4, ""+10);

Line fastLine11 = new Line(chart.getChart());
fastLine11.add(1, ""+1);
fastLine11.add(3, ""+2);
fastLine11.add(8, ""+3);
fastLine11.add(4, ""+10);

Line fastLine1 = new Line(chart.getChart());
fastLine1.add(10, ""+1);
fastLine1.add(20, ""+3);

Line fastLine4 = new Line(chart.getChart());
fastLine4.add(10, ""+1);
fastLine4.add(20, ""+2);
fastLine4.add(20, ""+3);
fastLine4.add(20, ""+4);
fastLine4.add(20, ""+7);
fastLine4.add(20, ""+8);
fastLine4.add(20, ""+9);
fastLine4.add(20, ""+10);

Line fastLine5 = new Line(chart.getChart());
fastLine5.add(10, ""+1);
fastLine5.add(20, ""+2);
fastLine5.add(20, ""+3);
fastLine5.add(20, ""+10);
fastLine5.add(20, ""+15);

frame.add(panel);
frame.setSize(600, 600);
frame.setVisible(true);
}
} 

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Oct 09, 2008 1:43 pm

Hi Varun,

Sorry but I'm not able to reproduce the problem you mention here. Could you please send us an image of what you get and let us know the TeeChart version you are using?

You can post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Chen
Newbie
Newbie
Posts: 43
Joined: Tue Mar 11, 2008 12:00 am
Contact:

Post by Chen » Thu Oct 09, 2008 2:23 pm

I have uploaded an image file to your server.
I am using 22, May 2008 version of Teechart for Java.

Thanks,
Varun

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Oct 09, 2008 2:43 pm

Hi Varun,

Thanks for the information. Sorry, I had missed repeated "10" label. Now I see which is the exact problem, each series overwrites previous series labels. Since last series (fastLine4) has less values than penultimate series (fastLine5), some labels from fastLine4 are still visible.

Which are the labels you expect to get?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Chen
Newbie
Newbie
Posts: 43
Joined: Tue Mar 11, 2008 12:00 am
Contact:

Post by Chen » Thu Oct 09, 2008 2:48 pm

Hi,

I want to see NO duplicate labels and a valid chart.
Sorry I did not understand your question.
If I take my example then I would like to see 1,2,3,4,7,8,9,10, 15. Am I correct? And each series would have a valid(x,y, text) point.

Thanks,
Varun

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Oct 09, 2008 3:04 pm

Hi Varun,
If I take my example then I would like to see 1,2,3,4,7,8,9,10, 15. Am I correct? And each series would have a valid(x,y, text) point.
This doesn't make much sense to me because the way you are populating your series, only providing a Y value, is the equivalent to populating series using X and Y values as shown here:

Code: Select all

        Line fastLine = new Line(myChart.getChart());
        fastLine.add(0, 2, ""+1);
        fastLine.add(1, 3, ""+3);
        fastLine.add(2, 4, ""+10);

        Line fastLine11 = new Line(myChart.getChart());
        fastLine11.add(0, 1, ""+1);
        fastLine11.add(1, 3, ""+2);
        fastLine11.add(2, 8, ""+3);
        fastLine11.add(3, 4, ""+10);

        Line fastLine1 = new Line(myChart.getChart());
        fastLine1.add(0, 10, ""+1);
        fastLine1.add(1, 20, ""+3);

        Line fastLine4 = new Line(myChart.getChart());
        fastLine4.add(0, 10, ""+1);
        fastLine4.add(1, 20, ""+2);
        fastLine4.add(2, 20, ""+3);
        fastLine4.add(3, 20, ""+4);
        fastLine4.add(4, 20, ""+7);
        fastLine4.add(5, 20, ""+8);
        fastLine4.add(6, 20, ""+9);
        fastLine4.add(7, 20, ""+10);

        Line fastLine5 = new Line(myChart.getChart());
        fastLine5.add(0, 10, ""+1);
        fastLine5.add(1, 20, ""+2);
        fastLine5.add(2, 20, ""+3);
        fastLine5.add(3, 20, ""+10);
        fastLine5.add(4, 20, ""+15); 
Given that code, for example, you are providing different labels for X=1 (labels are: 3,2,3,2,2) therefore the later is used. Also the same happens for X=3 (labels are: 4, 10).

To achieve what you request the only solution is using custom labels adding code below to your example.

Code: Select all

        myChart.getAxes().getBottom().getLabels().getItems().clear();
        
        myChart.getAxes().getBottom().getLabels().getItems().add(0.0, "1");
        myChart.getAxes().getBottom().getLabels().getItems().add(1.0, "2");
        myChart.getAxes().getBottom().getLabels().getItems().add(2.0, "3");
        myChart.getAxes().getBottom().getLabels().getItems().add(3.0, "4");
        myChart.getAxes().getBottom().getLabels().getItems().add(4.0, "7");
        myChart.getAxes().getBottom().getLabels().getItems().add(5.0, "8");
        myChart.getAxes().getBottom().getLabels().getItems().add(6.0, "9");
        myChart.getAxes().getBottom().getLabels().getItems().add(7.0, "10");
        myChart.getAxes().getBottom().getLabels().getItems().add(8.0, "15");
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply