Page 1 of 1

Bars should have equal width and distance should be proper

Posted: Thu Jul 30, 2009 11:47 am
by 13045482
I have this code-
Public Class BAR_ORIGINAL_MAXPOINT
Public Sub New()
InitializeComponent()
InitializeChart()
End Sub


Private Sub InitializeChart()
TChart1.Panel.Brush.Color = System.Drawing.SystemColors.ActiveCaptionText
TChart1.Panel.MarginTop = 2
TChart1.Size = New System.Drawing.Size(996, 312)
TChart1.TabIndex = 78

'
'
'
'
'
'
'
'
'
TChart1.Walls.Left.Brush.Solid = False
'
'
'
TChart1.Walls.Left.Pen.Color = System.Drawing.Color.FromArgb(CType(CType(254, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer))
Dim barSeriesBase As Steema.TeeChart.Styles.Bar
Dim barSeriesIncrement As Steema.TeeChart.Styles.Bar
Dim bsDecrement As Steema.TeeChart.Styles.Bar

barSeriesBase = New Steema.TeeChart.Styles.Bar
barSeriesIncrement = New Steema.TeeChart.Styles.Bar
bsDecrement = New Steema.TeeChart.Styles.Bar


barSeriesBase.Add(123, "Afffffffffffffffffffffffff")
barSeriesBase.Add(456, "dr")
barSeriesBase.Add(321, "rea")
barSeriesBase.Add(555, "gggrea")
barSeriesBase.Add(5554, "gggrea")
barSeriesBase.Add(321, "rea")
barSeriesBase.Add(555, "gggrea")
barSeriesBase.Add(5554, "gggrea")

barSeriesIncrement.Add(123, "A")
barSeriesIncrement.Add(456, "dr")
barSeriesIncrement.Add(321, "rea")
barSeriesIncrement.Add(444, "ggrea")
barSeriesIncrement.Add(4441, "ggrea")
barSeriesIncrement.Add(321, "rea")
barSeriesIncrement.Add(444, "ggrea")
barSeriesIncrement.Add(4441, "ggrea")

bsDecrement.Add(123, "A")
bsDecrement.Add(456, "dr")
bsDecrement.Add(321, "rea")
bsDecrement.Add(88, "kjkj")
bsDecrement.Add(881, "kjkj")
bsDecrement.Add(321, "rea")
bsDecrement.Add(88, "kjkj")
bsDecrement.Add(881, "kjkj")
TChart1.Series.Add(barSeriesBase)
TChart1.Series.Add(bsDecrement)
TChart1.Series.Add(barSeriesIncrement)
'barSeriesBase.BarWidthPercent = 20%
'bsDecrement.BarWidthPercent = 20%
'barSeriesIncrement.BarWidthPercent = 20%
'TChart1.Series(0).Clear()
'TChart1.Series(0).Add(123, "AB")
'TChart1.Series(0).Add(456, "dr")
'TChart1.Series(0).Add(321, "rea")
barSeriesBase.MultiBar = Steema.TeeChart.Styles.MultiBars.Stacked
'TChart1.Series.Add(New Steema.TeeChart.Styles.Bar())
'TChart1.Series(1).Clear()
'TChart1.Series(1).Add(221, "cd")
'TChart1.Series(1).Add(456, "bg")
'TChart1.Series(1).Add(321, "rea")
'TChart1.Series.Add(New Steema.TeeChart.Styles.Bar())
'TChart1.Series(2).Clear()
'TChart1.Series(2).Add(100, "csd")
'TChart1.Series(2).Add(456, "bsg")
'TChart1.Series(2).Add(321, "resa")
'TChart1.Series.Add(New Steema.TeeChart.Styles.Bar())
'TChart1.Series(3).Clear()
'TChart1.Series(3).Add(100, "csd")
'TChart1.Series(3).Add(456, "bsg")
'TChart1.Series(3).Add(321, "resa")
'TChart1.Series.Add(New Steema.TeeChart.Styles.Bar())
'TChart1.Series(4).Clear()
'TChart1.Series(4).Add(100, "csd")
'TChart1.Series(4).Add(456, "bsg")
'TChart1.Series(4).Add(321, "resa")
TChart1.Legend.CheckBoxes = True
TChart1.Legend.LegendStyle = Steema.TeeChart.LegendStyles.Series
TChart1.Axes.Bottom.Automatic = False
TChart1.Axes.Bottom.AutomaticMaximum = True
TChart1.Axes.Bottom.AutomaticMinimum = True
TChart1.Axes.Bottom.Labels.Angle = 90
TChart1.Walls.Bottom.Pen.Width = 1
TChart1.Axes.Left.Maximum = 1800
barSeriesBase.Marks.Visible = False
barSeriesIncrement.Marks.Visible = False
bsDecrement.Marks.Visible = False
TChart1.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom

' TChart1.Aspect.Chart3DPercent = 4
TChart1.Aspect.View3D = False

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TChart1.Page.MaxPointsPerPage = Val(Me.TextBox1.Text)
End Sub


End Class
==============================================
Now the issue is that i want that all bars should have same width and distance between them should be proper. That is if only 2 bars then they should not be at left and right ends, rather should have equi distance from ends and between them. the max bars i will show is upto 5 bars. the sissue is that as i increase bars the width of bars reduces. also when only 2 bars then the distance should be equi distance from ends and between them. how to do this?

Re: Bars should have equal width and distance should be proper

Posted: Thu Jul 30, 2009 11:51 am
by 13045482
also since the bar width is too much , i have added

barSeriesBase.BarWidthPercent = 20%

barSeriesIncrement.BarWidthPercent = 20%

barSeriesDecrement.BarWidthPercent = 20%

to above code now.

Re: Bars should have equal width and distance should be proper

Posted: Thu Jul 30, 2009 12:13 pm
by 13045482
Its a bit urgent, your swift reply will be highly appreciated.. just typing down the revised codea fter adding the above 3 lines->

The revised code is ->
Public Class BAR_ORIGINAL_MAXPOINT
Public Sub New()
InitializeComponent()
InitializeChart()
End Sub


Private Sub InitializeChart()
TChart1.Panel.Brush.Color = System.Drawing.SystemColors.ActiveCaptionText
TChart1.Panel.MarginTop = 2
TChart1.Size = New System.Drawing.Size(996, 312)
TChart1.TabIndex = 78

'
'
'
'
'
'
'
'
'
TChart1.Walls.Left.Brush.Solid = False
'
'
'
TChart1.Walls.Left.Pen.Color = System.Drawing.Color.FromArgb(CType(CType(254, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer))
Dim barSeriesBase As Steema.TeeChart.Styles.Bar
Dim barSeriesIncrement As Steema.TeeChart.Styles.Bar
Dim bsDecrement As Steema.TeeChart.Styles.Bar

barSeriesBase = New Steema.TeeChart.Styles.Bar
barSeriesIncrement = New Steema.TeeChart.Styles.Bar
bsDecrement = New Steema.TeeChart.Styles.Bar


barSeriesBase.Add(123, "Afffffffffffffffffffffffff")
barSeriesBase.Add(456, "dr")
barSeriesBase.Add(321, "rea")
barSeriesBase.Add(555, "gggrea")
barSeriesBase.Add(5554, "gggrea")
barSeriesBase.Add(321, "rea")
barSeriesBase.Add(555, "gggrea")
barSeriesBase.Add(5554, "gggrea")

barSeriesIncrement.Add(123, "A")
barSeriesIncrement.Add(456, "dr")
barSeriesIncrement.Add(321, "rea")
barSeriesIncrement.Add(444, "ggrea")
barSeriesIncrement.Add(4441, "ggrea")
barSeriesIncrement.Add(321, "rea")
barSeriesIncrement.Add(444, "ggrea")
barSeriesIncrement.Add(4441, "ggrea")

bsDecrement.Add(123, "A")
bsDecrement.Add(456, "dr")
bsDecrement.Add(321, "rea")
bsDecrement.Add(88, "kjkj")
bsDecrement.Add(881, "kjkj")
bsDecrement.Add(321, "rea")
bsDecrement.Add(88, "kjkj")
bsDecrement.Add(881, "kjkj")
TChart1.Series.Add(barSeriesBase)
TChart1.Series.Add(bsDecrement)
TChart1.Series.Add(barSeriesIncrement)
'barSeriesBase.BarWidthPercent = 20%
'bsDecrement.BarWidthPercent = 20%
'barSeriesIncrement.BarWidthPercent = 20%
'TChart1.Series(0).Clear()
'TChart1.Series(0).Add(123, "AB")
'TChart1.Series(0).Add(456, "dr")
'TChart1.Series(0).Add(321, "rea")
barSeriesBase.MultiBar = Steema.TeeChart.Styles.MultiBars.Stacked
'TChart1.Series.Add(New Steema.TeeChart.Styles.Bar())
'TChart1.Series(1).Clear()
'TChart1.Series(1).Add(221, "cd")
'TChart1.Series(1).Add(456, "bg")
'TChart1.Series(1).Add(321, "rea")
'TChart1.Series.Add(New Steema.TeeChart.Styles.Bar())
'TChart1.Series(2).Clear()
'TChart1.Series(2).Add(100, "csd")
'TChart1.Series(2).Add(456, "bsg")
'TChart1.Series(2).Add(321, "resa")
'TChart1.Series.Add(New Steema.TeeChart.Styles.Bar())
'TChart1.Series(3).Clear()
'TChart1.Series(3).Add(100, "csd")
'TChart1.Series(3).Add(456, "bsg")
'TChart1.Series(3).Add(321, "resa")
'TChart1.Series.Add(New Steema.TeeChart.Styles.Bar())
'TChart1.Series(4).Clear()
'TChart1.Series(4).Add(100, "csd")
'TChart1.Series(4).Add(456, "bsg")
'TChart1.Series(4).Add(321, "resa")
TChart1.Page.MaxPointsPerPage = 2
TChart1.Legend.CheckBoxes = True
TChart1.Legend.LegendStyle = Steema.TeeChart.LegendStyles.Series
TChart1.Axes.Bottom.Automatic = False
TChart1.Axes.Bottom.AutomaticMaximum = True
TChart1.Axes.Bottom.AutomaticMinimum = True
TChart1.Axes.Bottom.Labels.Angle = 90
TChart1.Walls.Bottom.Pen.Width = 1
TChart1.Axes.Left.Maximum = 1800
barSeriesBase.Marks.Visible = False
barSeriesIncrement.Marks.Visible = False
bsDecrement.Marks.Visible = False
TChart1.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom
barSeriesBase.BarWidthPercent = 20%

barSeriesIncrement.BarWidthPercent = 20%

bsDecrement.BarWidthPercent = 20%
'now
' TChart1.Aspect.Chart3DPercent = 4
TChart1.Aspect.View3D = False
'TChart1.Aspect.ZOffset = 0
' TChart1.Axes.Left.AutomaticMaximum = False
' TChart1.Axes.Bottom.Maximum = 3
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TChart1.Page.MaxPointsPerPage = Val(Me.TextBox1.Text)
End Sub


End Class

Re: Bars should have equal width and distance should be proper

Posted: Thu Jul 30, 2009 3:06 pm
by yeray
Hi shikha,

If you want both left space and right space to be exactly equal to the inter-bar increment, you'll see the "next bar" on the right or in the left if there is.
And note that in this particular case this increment is 1, so you could do:

Code: Select all

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim nPoints As Integer
        nPoints = Val(Me.TextBox1.Text)
        
        TChart1.Axes.Bottom.MinimumOffset = 0
        TChart1.Axes.Bottom.MaximumOffset = 0
        TChart1.Axes.Bottom.SetMinMax(barSeriesBase.XValues.Value(0) - 1, barSeriesBase.XValues.Value(nPoints - 1) + 1)
    End Sub

Re: Bars should have equal width and distance should be proper

Posted: Fri Jul 31, 2009 6:22 am
by 13045482
thanks but doing this shows me one bar extra.. ie for example...if i give 3 bars to display in no of bars to display textbox and click the button it shows 4 bars. i m using version 3.5.3470.15474.

Re: Bars should have equal width and distance should be proper

Posted: Fri Jul 31, 2009 7:56 am
by yeray
Hi shikha,

That's what I meant in my little explanation in the previous message.
I think that to view the "next bar" is a logical consequence of your demand. If you want the same distance between the bars to be from the last bar to the end of the bottom axis, it will coincide with "next bar" position. And that's why the left half of the next bar is shown.

If that's not the result you are expecting, please, try to explain what exactly you are trying to do. Probably a picture would help us to understand you.

Re: Bars should have equal width and distance should be proper

Posted: Fri Jul 31, 2009 8:07 am
by 13045482
ok, i am uploading a file which has pictorial representation of what i am looking for.

Re: Bars should have equal width and distance should be proper

Posted: Fri Jul 31, 2009 10:06 am
by 13045482
hi
i have uploaded bar_same_distance_same width.doc . please let me know if any other qs.Will really apreciate swift reply. thanks.

Re: Bars should have equal width and distance should be proper

Posted: Fri Jul 31, 2009 11:44 am
by yeray
Hi shikha,

If you want the same empty space in the left than in the right (X=Y in your picture), you could do as follows:

Code: Select all

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim nPoints As Integer
        nPoints = Val(Me.TextBox1.Text)
        
        TChart1.Axes.Bottom.MinimumOffset = 0
        TChart1.Axes.Bottom.MaximumOffset = 0

        Dim InterBarDistance As Double
        InterBarDistance = barSeriesBase.XValues.Value(1) - barSeriesBase.XValues.Value(0)

        TChart1.Axes.Bottom.SetMinMax(barSeriesBase.XValues.Value(0) - (InterBarDistance / 2), barSeriesBase.XValues.Value(nPoints - 1) + (InterBarDistance / 2))
    End Sub

Re: Bars should have equal width and distance should be proper

Posted: Mon Aug 03, 2009 1:20 pm
by 13045482
great thanx.. it works PERFECTLY in an independent code( which i sent u)..

A) BUT in my real code where there is some other stuff too, it works as far as distance is concerned but the only issue in there is taht the width of bars changes as No of bars changes( so if there is only one bar to display it shows VERY VERY wide bar and if there are 2 bars it shrinks the width a little , if there are 3 bars it shrinks the width a little more and so on)... on debugging i found that its showing
?barSeriesBase.BarWidthPercent
70
?barSeriesIncrement.BarWidthPercent
70
?barSeriesDecrement.BarWidthPercent
70

while i am not setting /changing barSeriesIncrement.BarWidthPercent,barSeriesDecrement.BarWidthPercent,barSeriesBase.BarWidthPercent anywhere !!! So how come it shows it as 70. More over what can be reason of ISSUE A) described above?

Re: Bars should have equal width and distance should be proper

Posted: Mon Aug 03, 2009 1:48 pm
by yeray
Hi shikha,

By default, the chart calculates the bar width to fit the chart width. If you want to disable this feature, you should assign a bar width using the CustomBarWidth property.

Re: Bars should have equal width and distance should be proper

Posted: Mon Aug 03, 2009 2:24 pm
by 13045482
Can you give me some example that how you set the bar width using custom property? Many thanks.

Re: Bars should have equal width and distance should be proper

Posted: Mon Aug 03, 2009 3:06 pm
by yeray
Hi shikha,

In your application, you could force the series width to be 20 doing something like this:

Code: Select all

barSeriesBase.CustomBarWidth = 20
barSeriesIncrement.CustomBarWidth = 20
barSeriesDecrement.CustomBarWidth = 20