Bar Series Question

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
bsierad
Newbie
Newbie
Posts: 16
Joined: Fri Feb 29, 2008 12:00 am

Bar Series Question

Post by bsierad » Tue Sep 15, 2009 8:02 pm

Hi,

Visual Studio 2005 SP2
VB.Net
Steema for TChart .Net V3

A fake example can be seen here:

http://www.envisionsoftware.com/es_imgs ... xample.gif


I want to create a simple Pareto chart. The # of bars will vary from use case to use case.
The problem I am experiencing has to do with the PLACEMENT of the Bar Series on the X Axis (Bottom Axis)
Because I can't position my Bar Series properly, my Line Series is out of sync with my Bar Series(s).

It is 'as if' the chart is 'auto formatting' the position and size of all my bar series.

The ultimate goal is to first drop my bar series(s) dynamically into the chart, and then, add one line series (on top of bar series) so the result is much like the example gif address given above.

Note: My line series is perfectly plotted on the chart. My debug output (telling me my x,y values for both, all bar series and my line series for the % are correct). Again, the problem is that the bars are NOT at the X Position specified when created and added to the TChart.chart object.

thanks,
ben

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

Re: Bar Series Question

Post by Narcís » Wed Sep 16, 2009 7:54 am

Hi ben,

Code below works fine for me here. Can you please check if that code snippet works fine at your end and, if necessary, modify it so that we can reproduce the problem here? Can you also let us know the exact TeeChart version you are using?

Code: Select all

			tChart1.Aspect.View3D = false;

			Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
			Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);

			line1.Pointer.Visible = true;

			for (int i = 0; i < 10; i++)
			{
				bar1.Add(i, i);
				line1.Add(i, i);
			}
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

bsierad
Newbie
Newbie
Posts: 16
Joined: Fri Feb 29, 2008 12:00 am

Re: Bar Series Question

Post by bsierad » Sat Sep 19, 2009 12:03 pm

Thanks, yes, your example works fine.

Version: V3 for .Net
3.2.2980.19082

My problem is just understanding how bar series behave based on the data put in.
All my data will have Y values and a label.

How about this example: My chart plots fruit types against quality:

Fruit Types:
Apples, Oranges, Bananas
Quality:
Ok, Good, Great

If I UNCOMMENT out the Oranges, it plots great (meaning, all measures are in my data source)

If my data source has NO data for Oranges (my COMMENTED lines) except for OK Quality, the chart displays my data incorrectly.

When I run this simple example, the output isn't what I was expecting, the chart drops GOOD and GREAT banana data under Oranges.
It is as if the chart plots data based on index, not label...

What am I doing wrong?

Dim bar1, bar2, bar3 As Steema.TeeChart.Styles.Bar

bar1 = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
With bar1
.Marks.Visible = True
.Marks.Style = Styles.MarksStyles.Value
.ColorEach = False
.Add(200, "Apples")
.Add(100, "Oranges")
.Add(50, "Bananas")
.Title = "OK"
End With

bar2 = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
With bar2
.Marks.Visible = True
.Marks.Style = Styles.MarksStyles.Value
.ColorEach = False
.Add(100, "Apples")
'.Add(50, "Oranges")
.Add(25, "Bananas")
.Title = "GOOD"
End With

bar3 = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
With bar3
.Marks.Visible = True
.Marks.Style = Styles.MarksStyles.Value
.ColorEach = False
.Add(50, "Apples")
'.Add(25, "Oranges")
.Add(12, "Bananas")
.Title = "GREAT"
End With

Exit Sub

thanks,
bsierad

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

Re: Bar Series Question

Post by Narcís » Mon Sep 21, 2009 8:26 am

Hi bsierad,

Thanks for the info.
Version: V3 for .Net
3.2.2980.19082
Please notice there are much newer versions available at the client download area.
If my data source has NO data for Oranges (my COMMENTED lines) except for OK Quality, the chart displays my data incorrectly.
The problem here is that if you use the Add(double y, string label) method override, TeeChart automatically adds sequential x values for each series and therefore, when omitting one of the values it carries a de-synchronisation of the bars. The solution is providing an x value to the Add method too so that bars are synchronised, for example:

Code: Select all

        bar1 = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
        With bar1
            .Marks.Visible = True
            .Marks.Style = Steema.TeeChart.Styles.MarksStyles.Value
            .ColorEach = False
            .Add(1, 200, "Apples")
            .Add(2, 100, "Oranges")
            .Add(3, 50, "Bananas")
            .Title = "OK"
        End With

        bar2 = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
        With bar2
            .Marks.Visible = True
            .Marks.Style = Steema.TeeChart.Styles.MarksStyles.Value
            .ColorEach = False
            .Add(1, 100, "Apples")
            '.Add(2, 50, "Oranges")
            .Add(3, 25, "Bananas")
            .Title = "GOOD"
        End With

        bar3 = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
        With bar3
            .Marks.Visible = True
            .Marks.Style = Steema.TeeChart.Styles.MarksStyles.Value
            .ColorEach = False
            .Add(1, 50, "Apples")
            '.Add(2, 25, "Oranges")
            .Add(3, 12, "Bananas")
            .Title = "GREAT"
        End With
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

Captell
Newbie
Newbie
Posts: 65
Joined: Fri Sep 18, 2009 12:00 am

Re: Bar Series Question

Post by Captell » Sun Apr 03, 2011 1:34 am

I know this topic is a bit old but I am trying to deal with data with character labels,where multiple series are stacked and each series may not have all the classifications. I have created a sample application that isllustrates a couple of problems.

I understand that adding these values to a bar graph using Add(double y, string label) will, as you pointed out, create a sequential number starting at 0, so when multiple series are added and not all classifications are present is every series there is a missalign that happens. The way around this, as per this post" is to useadd(double x, double y, string label).

The follwing image is explained below:
03-04-2011 11-24-09.png
03-04-2011 11-24-09.png (28.74 KiB) Viewed 13525 times
The first example shows the correctly aligned chart with two series "class a" and "class b". both series have the same number of points and are created with the following code.

Code: Select all

 bar = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
      bar.MultiBar = MultiBars.Side
      bar.Marks.Visible = False
      bar.Title = "Class a"
      bar.Add(10, "Week1")
      bar.Add(15, "Week2")
      bar.Add(20, "Week3")
      bar = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
      bar.MultiBar = MultiBars.Side
      bar.Marks.Visible = False
      bar.Title = "Class b"
      bar.Add(20, "Week1")
      bar.Add(25, "Week2")
      bar.Add(30, "Week3")
here we can see all is correct on the chart.
The second example shows the same data but now the first point of "class a" has been removed the bar is created with the following code. This chart shows the second bar of "class a" has sliped down to week 1. Also note the error in the labels onthe bottom axis.

Code: Select all

 bar = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
      bar.MultiBar = MultiBars.Side
      bar.Marks.Visible = False
      bar.Title = "Class a"

      '''' commented OUT bar.Add(10, "Week1")
      bar.Add(15, "Week2")
      bar.Add(20, "Week3")

      bar = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
      bar.MultiBar = MultiBars.Side
      bar.Marks.Visible = False
      bar.Title = "Class b"

      bar.Add(20, "Week1")
      bar.Add(25, "Week2")
      bar.Add(30, "Week3")

The third example shows the same data as the second but with a hard coded Y value, created with the following code. Note now that the bars are in their correct position but the label from the first group "Week1" is missing.

Code: Select all

      bar = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
      bar.MultiBar = MultiBars.Side
      bar.Marks.Visible = False
      bar.Title = "Class a"

      '''' commented OUT bar.Add(10, "Week1")
      bar.Add(2, 15, "Week2")
      bar.Add(3, 20, "Week3")

      bar = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
      bar.MultiBar = MultiBars.Side
      bar.Marks.Visible = False
      bar.Title = "Class b"

      bar.Add(1, 20, "Week1")
      bar.Add(2, 25, "Week2")
      bar.Add(3, 30, "Week3")
The final example is what happens when you change stacking from "side" to "stack" using the previous example.

Can you provide a suitable workaround for these problems, better still can you fix TCHART so that it correctly draws and aligns bars, and lines that have text based labels and no numerical order.

Thanks.

Here is the form that created the examples.
form1.zip
(3.66 KiB) Downloaded 566 times
Adrian Heald
Director
ITSM Reporting Services Pty Ltd
http://www.reportingservices.com

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Bar Series Question

Post by Sandra » Mon Apr 04, 2011 3:05 pm

Hello Captell,

I could reproduce your problem and I have added it in bug list report with number [TF02015472].We will try to fix it to next maintenance releases of TeeChart.Net. On the other hand, I have modified your code using custom labels to axes and labels are correct.
WindowsApplication7.zip
(19.94 KiB) Downloaded 600 times
Could you tell us, if previous code works are you expected?
I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / 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

Captell
Newbie
Newbie
Posts: 65
Joined: Fri Sep 18, 2009 12:00 am

Re: Bar Series Question

Post by Captell » Mon Apr 04, 2011 7:46 pm

Thanks for the quick reply, however while your solution

Code: Select all

 TChart1.Axes.Bottom.Labels.Items.Clear()
      For i As Integer = 0 To TChart1.Series(1).Count - 1
         TChart1.Axes.Bottom.Labels.Items.Add(TChart1.Series(1).XValues(i), TChart1.Series(1).Labels.Item(i))
      Next
does fix the missing label for the first group of bars it only work because you know the series(1) has all data points. In my application I don't have any control over the user, they can import any data and produce any chart so this doesn't really help.

And there is still the issue with stacking, see the 4th image above.

If I may make a suggestion. Getting this sort of functionality correct is such a fundamental requirement of a charting tool. What we should be able to do as a developer utilising TCHART is simply call it passing Y values and X labels and have the labels and bars correctly aligned. The current method of drawing bars based only on the ordinal position is flawed for character Xvalues. Can we have a series.add overload that allows a Yvalue and an Xvalue as string and then works out the correct position based on the xvalues from any existing series. This would, for the first series, simply plot the bars based on ordinal position, for second and subsequent series it would need to either match the new series xvalue with any existing xvalues or it would need to insert the new bar where appropriate if the new bar xvalue didn't already exist in the chart.

Thanks.
Adrian Heald
Director
ITSM Reporting Services Pty Ltd
http://www.reportingservices.com

Captell
Newbie
Newbie
Posts: 65
Joined: Fri Sep 18, 2009 12:00 am

Re: Bar Series Question

Post by Captell » Mon Apr 04, 2011 9:52 pm

Further,
Try the example with this set of data and you will see what I mean regarding knowing the series
bar = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
bar.MultiBar = MultiBars.Side
bar.Marks.Visible = False
bar.Title = "Class a"

bar.Add(0, 10, "Week1")
bar.Add(1, 15, "Week2")
bar.Add(2, 20, "Week3")

bar = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
bar.MultiBar = MultiBars.Side
bar.Marks.Visible = False
bar.Title = "Class b"

' COMMENTED OUT bar.Add(0, 20, "Week1")
bar.Add(1, 25, "Week2")
bar.Add(2, 30, "Week3")
Adrian Heald
Director
ITSM Reporting Services Pty Ltd
http://www.reportingservices.com

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Bar Series Question

Post by Sandra » Tue Apr 05, 2011 10:40 am

Hello Captell,

After do many tests I inform you that currently if you want of labels work correctly you need have the same number of points for each series you add in the chart, so I have change bug (TF02015472) to future request. This change doesn't mean it is less important only change its internally category so is not an error is a change of behave. On the other hand, I suggest you three options you can use at the moment:

First: You can add only a label in null point as do with next line of code:

Code: Select all

            
        bar.Add("Week1")
        bar.Add(15, "Week2")
        bar.Add(20, "Week3")
Second: You can add the first point and after set Null the point as do in below lines, using SetNull() method:

Code: Select all

        
         bar.Add(10, "Week1")
         bar.SetNull(0)
         bar.Add(15, "Week2")
         bar.Add(20, "Week3")
Third: Doing the same as previous but instead of use SetNull set the color of first point as transparent:

Code: Select all

bar.Add(10, "Week1",Color.Transparent)
Also, if you don't like next options, you can overwrite the method add and create your own method.

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / 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

Captell
Newbie
Newbie
Posts: 65
Joined: Fri Sep 18, 2009 12:00 am

Re: Bar Series Question

Post by Captell » Wed Apr 06, 2011 8:38 pm

Thanks Sandra,
I've worked through the different ADD methods you have suggested and found that bar.Add("Week1") works in that if I know where the gaps are in the series as I'm adding the points I can use bar.Add("Week1") to add a "spacer" after which stacking works as expected.

These options don't allow stacking to work

Code: Select all

bar.Add(10, "Week1")
bar.SetNull(0)

bar.Add(10, "Week1",Color.Transparent)
However bar.add(10,0,"Week1") does allow stacking to work ok.

So based on this I've created this litle FixLabels function. Unfortunately it's still not working correctly when the bars are added sequentially i.e. if I add bars to the series using

Code: Select all

ipoint = bar.Add(10)
bar(ipoint).Label = "Week1"
the xvalues are automatically set as sequential starting from 0, so if my first series has "week1" and "Week3" i.e. missing "week2" the xvalues are 0 and 1. If a second series has "week1", "week2" and "week3" the fixLabels routine needs to insert a "spacer" between "week1" and "week3" of the first series. Unfortunately, I can't find an ADD overload that will do this. If, on the other hand, I add the data using bar.Add(0, 20, "Week1") overload, i.e. I set the Xvalue myself and for the first series I leave a gap for "week2", i.e. the xvalues are 0 and 2 the fixLabels routine works fine. The problem is that I don't know what my data is until the user creates each series so I can't leave a gap. Can you suggest an ADD overload that will INSERT a bar? Or do you have another solution to this problem.

Code: Select all

 Private Sub fixLabels()
      Dim bContinue As Boolean

      For x As Integer = 0 To TChart1.Series.Count - 1
         For y As Integer = 0 To TChart1.Series.Count - 1
            If TChart1.Series(x).Title <> TChart1.Series(y).Title Then
               bContinue = True
               Do While bContinue
                  bContinue = False
                  For i As Integer = 0 To TChart1.Series(x).Labels.Count - 1
                     If TChart1.Series(x).Labels(i) <> TChart1.Series(y).Labels(i) And _
                        TChart1.Series(x).Labels(i) <> "" And _
                        TChart1.Series(y).Labels(i) <> "" Then
                        If TChart1.Series(x).Labels(i) > TChart1.Series(y).Labels(i) Then
                           TChart1.Series(x).Add(i, 0, TChart1.Series(y).Labels(i))
                           TChart1.Series(x).SetNull(i)
                        Else
                           TChart1.Series(y).Add(i, 0, TChart1.Series(x).Labels(i))
                           TChart1.Series(y).SetNull(i)
                        End If
                        bContinue = True
                        Exit For
                     End If
                  Next
               Loop
            End If
         Next
      Next
   End Sub
You can implement this by including fixLabels() at the end of the button2 click event. To try a different add method use

Code: Select all

 bar = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
      bar.MultiBar = MultiBars.Side
      bar.Marks.Visible = False
      bar.Title = "Class a"
      Dim ipoint As Integer

      ipoint = bar.Add(10)
      bar(ipoint).Label = "Week1"
      'ipoint = bar.Add(11)
      'bar(ipoint).Label = "Week2"
      ipoint = bar.Add(12)
      bar(ipoint).Label = "Week3"

      'bar.Add(0, 10, "Week1")
      ''bar.Add(1, 11, "Week2")
      'bar.Add(2, 12, "Week3")

      bar = New Steema.TeeChart.Styles.Bar(TChart1.Chart)
      bar.MultiBar = MultiBars.Side
      bar.Marks.Visible = False
      bar.Title = "Class b"

      ipoint = bar.Add(0, 20)
      bar(ipoint).Label = "Week1"
      ipoint = bar.Add(1, 21)
      bar(ipoint).Label = "Week2"
      ipoint = bar.Add(2, 22)
      bar(ipoint).Label = "Week3"
Adrian Heald
Director
ITSM Reporting Services Pty Ltd
http://www.reportingservices.com

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Bar Series Question

Post by Sandra » Mon Apr 11, 2011 2:59 pm

Hello Captell,

Sorry for the delay.

These options don't allow stacking to work

Code: Select all

bar.Add(10, "Week1")
bar.SetNull(0)

bar.Add(10, "Week1",Color.Transparent)
However bar.add(10,0,"Week1") does allow stacking to work ok.
I suggest you setting Y value to zero in the same moment you do SetNull() using same index to both cases, as do in next lines of code:

Code: Select all

       bar.Add(10, "Week1")
        bar.SetNull(0)
        bar.YValues(0) = 0
the xvalues are automatically set as sequential starting from 0, so if my first series has "week1" and "Week3" i.e. missing "week2" the xvalues are 0 and 1. If a second series has "week1", "week2" and "week3" the fixLabels routine needs to insert a "spacer" between "week1" and "week3" of the first series. Unfortunately, I can't find an ADD overload that will do this. If, on the other hand, I add the data using bar.Add(0, 20, "Week1") overload, i.e. I set the Xvalue myself and for the first series I leave a gap for "week2", i.e. the xvalues are 0 and 2 the fixLabels routine works fine. The problem is that I don't know what my data is until the user creates each series so I can't leave a gap. Can you suggest an ADD overload that will INSERT a bar? Or do you have another solution to this problem.
The bar of series, that corresponds of label week3, doesn't change its position because you need change XValue() to value of position of label week3, summing one to XValue() to achieve the correct position the point of the bar. So, I have modified your code FixLabels() and now works fine for me here:

Code: Select all

Private Sub fixLabels()
        Dim bContinue As Boolean
        For x As Integer = 0 To TChart1.Series.Count - 1
            For y As Integer = 0 To TChart1.Series.Count - 1
                If TChart1.Series(x).Title <> TChart1.Series(y).Title Then
                    bContinue = True
                    Do While bContinue
                        bContinue = False
                        For i As Integer = 0 To TChart1.Series(x).Labels.Count - 1
                            If TChart1.Series(x).Labels(i) <> TChart1.Series(y).Labels(i) And TChart1.Series(x).Labels(i) <> "" And TChart1.Series(y).Labels(i) <> "" Then
                                If TChart1.Series(x).Labels(i) > TChart1.Series(y).Labels(i) Then
                                    TChart1.Series(x).XValues.Value(i) = TChart1.Series(x).XValues.Value(i) + 1
                                    TChart1.Series(x).Add(i, 0, TChart1.Series(y).Labels(i))
                                    TChart1.Series(x).SetNull(i)
                                Else
                                    TChart1.Series(y).XValues.Value(i) = TChart1.Series(y).XValues.Value(i) + 1
                                    TChart1.Series(y).Add(i, 0, TChart1.Series(x).Labels(i))
                                    TChart1.Series(y).SetNull(i)
                                End If
                                bContinue = True
                                Exit For
                            End If
                        Next
                    Loop
                End If
            Next
        Next
On the other hand, I recommend you are very careful using method of FixLabels(), so you are manipulated index of series and values of series and it can cause some problems.

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / 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