Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSChart Graph Problem 1

Status
Not open for further replies.

norason

Programmer
Jan 28, 2009
139
US
I'm trying to draw a graph that climbs for the first half, and descends for the second.

This code climbs just fine, but when I try to descend, it doesn't show anything.

If I change the MinusData = MinusData - 1
code to MinusData = MinusData + 1, it keeps climbing.

The numbers are actually descending from 65 to 1, but the chart doesn't follow.

What am I missing?

Dim arr(1 To 126, 1 To 7) ' 125 rows, 7 lines - 1 flow, 3-2pair windows

Dim PlusData As Integer 'test data - move data positive
Dim MinusData As Integer
PlusData = 1
MinusData = 66
Dim DataPoints(1 To 126, 1 To 1) 'total number of data points

'this is the up plus data
For PlusPoints = 1 To 65 '1st half of the datapoints going up
DataPoints(PlusData, 1) = PlusData
PlusData = PlusData + 1
Next PlusPoints

'this is the down minus data
For MinusPoints = 66 To 124 '2nd half of the datapoints going down
DataPoints(MinusData, 1) = MinusData
MinusData = MinusData - 1
Debug.Print MinusData
Debug.Print DataPoints(MinusData, 1)
Next MinusPoints


Thanks,

Gary
 



Gary,

Here's a tighter version, but WHERE is your CHART???
Code:
    Dim i As Integer, inc As Integer, j As Integer
    Dim DataPoints(1 To 126)               'total number of data points
    
    j = 1
    For i = 1 To UBound(DataPoints, 1)
        Select Case i
            Case Is < 66
                inc = 1
            Case Else
                inc = -1
        End Select
        DataPoints(i) = j
        j = j + inc
        Debug.Print DataPoints(i)
    Next

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks for the new code - I'm such a newbie that I keep doing things the hard way.

Here's the code:

Private Sub cmdDrawGraph_Click()
Dim TotalNumberOfGraphs As Integer 'this is the number of graphs available
Dim arr(1 To 126, 1 To 7) ' 125 rows, 7 lines - 1 flow, 3-2pair windows

Dim PlusData As Integer 'test data - move data positive
Dim MinusData As Integer
PlusData = 1
MinusData = 66
Dim DataPoints(1 To 126, 1 To 1) 'total number of data points

'this is the up plus data
For PlusPoints = 1 To 65 '1st half of the datapoints going up
DataPoints(PlusData, 1) = PlusData
PlusData = PlusData + 1
Next PlusPoints

'this is the down minus data
For MinusPoints = 66 To 124 '2nd half of the datapoints going down
DataPoints(MinusData, 1) = MinusData
MinusData = MinusData - 1
Debug.Print MinusData
Debug.Print DataPoints(MinusData, 1)
Next MinusPoints


Dim m As Variant 'draws the window lines
For m = 1 To 60
arr(m, 2) = 100.5
arr(m, 3) = 300.2
Next m
For n = 40 To 90
arr(n, 4) = 600.3
arr(n, 5) = 700.9
Next n
For q = 70 To 125
arr(q, 6) = 100.6
arr(q, 7) = 200.6
Next q 'draws the window lines
With MSChart1
.ChartType = VtChChartType2dLine
.ShowLegend = True
.Plot.Axis(VtChAxisIdX).Labels(1).VtFont.Name = ariel
.Plot.Axis(VtChAxisIdX).Labels(1).VtFont.Size = 12
.Plot.Axis(VtChAxisIdX).Labels(1).VtFont.Style = Bold
.Plot.Axis(VtChAxisIdX).Labels(1).VtFont.VtColor.Set 204, 204, 204
.TitleText = "IDI BP5 PUMP FLOW GRAPH"
.ChartData = DataPoints
With .DataGrid
.SetSize 1, 7, 126, 7 '(rowLabelCount, columnLabelCount, dataRowCount, columnLabelCount)
Dim intIndex As Integer '*******************
' Dim strAbbrev(1 To 16) As String 'Names the Rows
' strAbbrev(1) = "0 ms"
'strAbbrev(2) = "3 ms"
'strAbbrev(3) = "5 ms"
'strAbbrev(4) = "7 ms"
'strAbbrev(5) = "9 ms"
' strAbbrev(6) = "10 ms"
' strAbbrev(7) = "13 ms"
' strAbbrev(8) = "15 ms"
' strAbbrev(9) = "16 ms"
'strAbbrev(10) = "17 ms"
'strAbbrev(11) = "19 ms"
' strAbbrev(12) = "23 ms"
' strAbbrev(13) = "26 ms"
' strAbbrev(14) = "29 ms"
'strAbbrev(15) = "33 ms"
'strAbbrev(16) = "36 ms"
MSChart1.RowCount = 126
'For intIndex = 1 To 16
' MSChart1.Row = intIndex
'MSChart1.RowLabel = strAbbrev(intIndex) 'Names the Rows
' Next intIndex '********************
End With
With .Plot
With .Axis(VtChAxisIdY).ValueScale
.Auto = False
.Minimum = 0
.Maximum = 1000
End With
With .Axis(VtChAxisIdX).AxisGrid
.MajorPen.VtColor.Set 204, 204, 204
.MajorPen.Width = 2
.MinorPen.VtColor.Set 204, 204, 204
.MinorPen.Width = 2
End With
With .Axis(VtChAxisIdY).AxisGrid
.MajorPen.VtColor.Set 204, 204, 204
.MajorPen.Width = 2
.MinorPen.VtColor.Set 204, 204, 204
.MinorPen.Width = 2
End With
With .SeriesCollection
.Item(1).LegendText = "Flow Data"
.Item(2).LegendText = "#1 Low Limit"
.Item(3).LegendText = "#1 High Limit"
.Item(4).LegendText = "#2 Low Limit"
.Item(5).LegendText = "#2 High Limit"
.Item(6).LegendText = "#3 Low Limit"
.Item(7).LegendText = "#3 HighLimit"
.Item(2).Pen.Style = VtPenStyleDitted
.Item(4).Pen.Style = VtPenStyleDitted
.Item(5).Pen.Style = VtPenStyleDashed
.Item(6).Pen.Style = VtPenStyleDitted
.Item(7).Pen.Style = VtPenStyleDashed
'With .Item(1).DataPoints(-1) 'controls text for flow line - grid too small - can't see the text
' .DataPointLabel.LocationType = VtChLabelLocationTypeAbovePoint
' .DataPointLabel.VtFont.VtColor.Set 0, 0, 0 '# black text
' .Brush.FillColor.Set 255, 0, 0 '# red line
'End With
With .Item(2).DataPoints(-1)
.DataPointLabel.VtFont.VtColor.Set 0, 102, 255 '# blue
.Brush.FillColor.Set 0, 102, 255
End With
With .Item(3).DataPoints(-1)
.DataPointLabel.VtFont.VtColor.Set 0, 102, 255 '# blue
.Brush.FillColor.Set 0, 102, 255
End With
With .Item(4).DataPoints(-1)
.DataPointLabel.VtFont.VtColor.Set 0, 204, 0 '# green
.Brush.FillColor.Set 0, 204, 0
End With
With .Item(5).DataPoints(-1)
.DataPointLabel.VtFont.VtColor.Set 204, 204, 204 '# green
.Brush.FillColor.Set 0, 204, 0
End With
With .Item(6).DataPoints(-1)
.DataPointLabel.VtFont.VtColor.Set 205, 153, 0 '# brown
.Brush.FillColor.Set 205, 153, 0
End With
With .Item(7).DataPoints(-1)
.DataPointLabel.VtFont.VtColor.Set 205, 153, 0 '# brown
.Brush.FillColor.Set 205, 153, 0
End With
End With '#seriescoll
End With '# plot
End With '#chart
End Sub


Thanks,

Gary
 
Here's the code I ended up with - thanks for the help!

Private Sub cmdDrawGraph_Click()
Dim arr(1 To 125, 1 To 7) ' 125 rows, 7 lines - 1 flow, 3-2pair windows
Dim i As Integer, inc As Integer, j As Integer
j = 1
For i = 1 To UBound(arr, 1)
Select Case i
Case Is < 66
inc = 1
Case Else
inc = -1
End Select
arr(i, 1) = j
j = j + inc
Next
Dim m As Variant 'draws the window lines
For m = 1 To 60
arr(m, 2) = 50.5
arr(m, 3) = 30.2
Next m
For n = 40 To 90
arr(n, 4) = 60.3
arr(n, 5) = 70.9
Next n
For q = 70 To 125
arr(q, 6) = 10.6
arr(q, 7) = 20.6
Next q 'draws the window lines
With MSChart1
.ChartType = VtChChartType2dLine
.ShowLegend = True
.Plot.Axis(VtChAxisIdX).Labels(1).VtFont.Name = ariel
.Plot.Axis(VtChAxisIdX).Labels(1).VtFont.Size = 12
.Plot.Axis(VtChAxisIdX).Labels(1).VtFont.Style = Bold
.Plot.Axis(VtChAxisIdX).Labels(1).VtFont.VtColor.Set 204, 204, 204
.TitleText = "IDI BP5 PUMP FLOW GRAPH"
.ChartData = arr
With .DataGrid
.SetSize 1, 7, 125, 7 '(rowLabelCount, columnLabelCount, dataRowCount, columnLabelCount)
Dim intIndex As Integer '*******************
MSChart1.RowCount = 125
End With
With .Plot
With .Axis(VtChAxisIdY).ValueScale
.Auto = False
.Minimum = 0
.Maximum = 100
End With
With .Axis(VtChAxisIdX).AxisGrid
.MajorPen.VtColor.Set 204, 204, 204
.MajorPen.Width = 2
.MinorPen.VtColor.Set 204, 204, 204
.MinorPen.Width = 2
End With
With .Axis(VtChAxisIdY).AxisGrid
.MajorPen.VtColor.Set 204, 204, 204
.MajorPen.Width = 2
.MinorPen.VtColor.Set 204, 204, 204
.MinorPen.Width = 2
End With
With .SeriesCollection
.Item(1).LegendText = "Flow Data"
.Item(2).LegendText = "#1 Low Limit"
.Item(3).LegendText = "#1 High Limit"
.Item(4).LegendText = "#2 Low Limit"
.Item(5).LegendText = "#2 High Limit"
.Item(6).LegendText = "#3 Low Limit"
.Item(7).LegendText = "#3 HighLimit"
.Item(2).Pen.Style = VtPenStyleDitted
.Item(4).Pen.Style = VtPenStyleDitted
.Item(5).Pen.Style = VtPenStyleDashed
.Item(6).Pen.Style = VtPenStyleDitted
.Item(7).Pen.Style = VtPenStyleDashed
With .Item(1).DataPoints(-1) 'controls text for flow line - grid too small - can't see the text
.DataPointLabel.LocationType = VtChLabelLocationTypeAbovePoint
.DataPointLabel.VtFont.VtColor.Set 0, 0, 0 '# black text
.Brush.FillColor.Set 255, 0, 0 '# red line
End With
With .Item(2).DataPoints(-1)
.DataPointLabel.VtFont.VtColor.Set 0, 102, 255 '# blue
.Brush.FillColor.Set 0, 102, 255
End With
With .Item(3).DataPoints(-1)
.DataPointLabel.VtFont.VtColor.Set 0, 102, 255 '# blue
.Brush.FillColor.Set 0, 102, 255
End With
With .Item(4).DataPoints(-1)
.DataPointLabel.VtFont.VtColor.Set 0, 204, 0 '# green
.Brush.FillColor.Set 0, 204, 0
End With
With .Item(5).DataPoints(-1)
.DataPointLabel.VtFont.VtColor.Set 204, 204, 204 '# green
.Brush.FillColor.Set 0, 204, 0
End With
With .Item(6).DataPoints(-1)
.DataPointLabel.VtFont.VtColor.Set 205, 153, 0 '# brown
.Brush.FillColor.Set 205, 153, 0
End With
With .Item(7).DataPoints(-1)
.DataPointLabel.VtFont.VtColor.Set 205, 153, 0 '# brown
.Brush.FillColor.Set 205, 153, 0
End With
End With '#seriescoll
End With '# plot
End With '#chart
End Sub


Gary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top