Page 1 of 1

Bar chart query.

Posted: Tue Oct 05, 2010 7:34 pm
by 9530487
Can someone try the VB code below?

The first bar has a X value of "0", but appears on the plot at approximately -3. What is going on?


Code: Select all

Private Sub DrawBar()
Dim i As Long

TChart1.RemoveAllSeries
For i = 0 To 5
    TChart1.AddSeries scBar
    TChart1.Series(i).AddXY i, i * 2, "", TChart1.Series(i).Color
Next i
End Sub

Re: Bar chart query.

Posted: Wed Oct 06, 2010 10:07 am
by narcis
Hi Tony,

I'm afraid this is a bug I have added to the defect list (TV52015189) to be fixed.

Re: Bar chart query.

Posted: Wed Oct 06, 2010 10:12 am
by 9530487
Any idea when? I have customers waiting.

Re: Bar chart query.

Posted: Wed Oct 06, 2010 10:17 am
by narcis
Hi Tony,

I can't give you an estimate date for now but this is a high-priority item in the list.

Re: Bar chart query.

Posted: Wed Oct 06, 2010 11:20 am
by narcis
Hi Tony,

Thinking a little bit further about this issue, the stacking algorithm will work correctly *only* if all series have the same number of points and point x values coincide. If this is not the case, you'll have to use AddNullXY method to add "missing points". I'd use the following approach:

1) Make a list of all available (pool) of x values.
2) For individual series, cycle through (1) and use AddXY if point (x,y) exists and AddNullXY if specific point (x,y) does not exist for this series.

An easier alternative is setting MultiBar to mbNone, for example:

Code: Select all

Private Sub Form_Load()
    Dim i As Long
    
    TChart1.RemoveAllSeries
    For i = 0 To 5
        TChart1.AddSeries scBar
        TChart1.Series(i).asBar.MultiBar = mbNone
        TChart1.Series(i).asBar.BarWidthPercent = 20
        TChart1.Series(i).AddXY i, i * 2, "", TChart1.Series(i).Color
    Next i
End Sub
So we have closed the issue in the bug list.

Re: Bar chart query.

Posted: Wed Oct 06, 2010 11:38 am
by 9530487
So we have closed the issue in the bug list.
Are you serious? How can anyone possibly make use of a chart component where the axes are not labelled correctly?

There are two series types now that do not label the axes correctly (gantt and bar).

This is a really serious bug.

Re: Bar chart query.

Posted: Wed Oct 06, 2010 1:01 pm
by narcis
Hi Tony,

This is how stacked series are designed. For stacking to work you need to have same number of points in all series and all of them should have same X values. Setting Multibar to mbNone doesn't label series wrongly but it may be nicer in 2D. There are 2 options here:

1. Set MultiBar to none and the chart to 2D view:

Code: Select all

Private Sub Form_Load()
    Dim i As Long
       
    TChart1.RemoveAllSeries
    TChart1.Aspect.View3D = False
    For i = 0 To 5
        TChart1.AddSeries scBar
        TChart1.Series(i).asBar.MultiBar = mbNone
        TChart1.Series(i).asBar.BarWidthPercent = 20
        TChart1.Series(i).AddXY i, i * 2, "", TChart1.Series(i).Color
    Next i
End Sub
2. Add same X values for all series setting to null the points which should not be displayed in the chart.

Code: Select all

Private Sub Form_Load()
    Dim i As Long
       
    TChart1.RemoveAllSeries
    TChart1.Aspect.View3D = False
    For i = 0 To 5
        TChart1.AddSeries scBar
        
        For j = 0 To 5
            TChart1.Series(i).AddXY j, i * 2, "", TChart1.Series(i).Color
            
            If i <> j Then
                TChart1.Series(i).SetNull j
            End If
        Next
    Next i

Re: Bar chart query.

Posted: Wed Oct 06, 2010 1:13 pm
by 9530487
My original query is not related to stacking in any way. It's basic code to draw some bars, and the x axis labels are completely wrong.

I don't want stacked series in this case, I just want the axis labelled correctly.

Re: Bar chart query.

Posted: Wed Oct 06, 2010 1:19 pm
by narcis
Hi Tony,

Yes, I understand but by default Bar series are set to MultiBar = mbSide. That's why I'm saying that if you are using several bar series the way you are you should either set MultiBar to mbNone or add null values where necessary. Actually, the example you sent would be easier using one single bar series, you can already have a different color for each series:

Code: Select all

Private Sub Form_Load()
    Dim i As Long
   
    TChart1.RemoveAllSeries
    TChart1.AddSeries scBar
    TChart1.Series(0).asBar.BarWidthPercent = 20
    TChart1.Series(0).ColorEachPoint = True
    
    For i = 0 To 5
        TChart1.Series(0).AddXY i, i * 2, "", clTeeColor
    Next i
End Sub

Re: Bar chart query.

Posted: Wed Oct 06, 2010 1:46 pm
by narcis
Hi Tony,

Another option is setting Multibar to mbSideAll:

Code: Select all

Private Sub Form_Load()
  Dim i As Integer
  
  For i = 0 To 5
    TChart1.AddSeries scBar
    TChart1.Series(i).AddXY i, i * 2, "", TChart1.Series(i).Color
    TChart1.Series(i).asBar.MultiBar = mbSideAll
  Next i
End Sub