home *** CD-ROM | disk | FTP | other *** search
Wrap
VERSION 4.00 Begin VB.Form Form1 Caption = "Scrolling Chart Demo" ClientHeight = 6735 ClientLeft = 1035 ClientTop = 1710 ClientWidth = 7035 Height = 7425 Icon = "scroll.frx":0000 Left = 975 LinkTopic = "Form1" ScaleHeight = 6735 ScaleWidth = 7035 Top = 1080 Width = 7155 Begin VB.HScrollBar HScroll1 Height = 255 Left = 60 TabIndex = 1 Top = 6420 Width = 6915 End Begin VB.Label lblTitle Alignment = 2 'Center Caption = "Dow Jones Average" BeginProperty Font name = "Times New Roman" charset = 0 weight = 400 size = 24 underline = 0 'False italic = 0 'False strikethrough = 0 'False EndProperty Height = 615 Left = 60 TabIndex = 3 Top = 60 Width = 6915 End Begin VB.Label lblinfo Alignment = 2 'Center Appearance = 0 'Flat BackColor = &H80000005& BackStyle = 0 'Transparent Caption = "Information" ForeColor = &H80000008& Height = 255 Left = 60 TabIndex = 2 Top = 720 Width = 6915 End Begin VCIFiLib.VtChart VtChart1 Height = 5355 Left = 60 TabIndex = 0 Top = 1020 Width = 6915 _version = 65536 _extentx = 12197 _extenty = 9446 _stockprops = 96 borderstyle = 1 filename = "scroll.frx":030A End Begin VB.Menu mnuChartTypeHead Caption = "&Chart Type" Begin VB.Menu mnuChartType Caption = "2D Line" Index = 0 End Begin VB.Menu mnuChartType Caption = "2D Area" Index = 1 End Begin VB.Menu mnuChartType Caption = "3D Line" Checked = -1 'True Index = 2 End Begin VB.Menu mnuChartType Caption = "3D Area" Index = 3 End Begin VB.Menu mnuChartType Caption = "3D Step" Index = 4 End End Begin VB.Menu mnuSetDaysVisible Caption = "&Set Days Visible!" End Attribute VB_Name = "Form1" Attribute VB_Creatable = False Attribute VB_Exposed = False Option Explicit Option Base 1 Dim DJData() As Double Dim gNumDataRows% Sub SetInfoLabel(offset%) lblInfo.Caption = " Dow Jones Average on " & _ Format(DJData(HScroll1.value + offset, 1), "d mmmm yyyy") & _ " was " & DJData(HScroll1.value + offset, 2) End Sub Sub ShowView(startingAt%) Dim i%, numRows%, min!, max!, temp# Dim numLabels%, label$ numRows = HScroll1.LargeChange '' If the user has scrolled to the end of the data, change '' the startingAt value so the entire chart can be viewed. '' This catches the case where the user has large window '' and wants to scroll to the end. If startingAt > 1 And startingAt > gNumDataRows - numRows Then startingAt = gNumDataRows - numRows End If VtChart1.RowCount = numRows '' The dimmensions of the array must match the dimmensions '' of the chart you want to fill. You must always use a 2D '' array even if you are copying in one row of data. ReDim theData(numRows, 1) As Double max = 0 min = 10000 For i = 1 To numRows temp = DJData(i + startingAt, 2) theData(i, 1) = temp max = IIf(temp > max, temp, max) min = IIf(temp < min, temp, min) Next i VtChart1.CopyDataFromArray 1, 1, numRows, 1, theData '' AutoScale will have a minimum at zero. We set min '' and max manually here VtChart1.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = Int((max + 20) / 10) * 10 VtChart1.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = Int((min - 20) / 10) * 10 '' Clear any old datapoint labels Dim DataPoint As Object With VtChart1.Plot.SeriesCollection.Item(1) For Each DataPoint In .DataPoints DataPoint.DataPointLabel.ResetCustomLabel Next DataPoint End With '' Set a new label for only the last datapoint With VtChart1.Plot.SeriesCollection.Item(1).DataPoints.Item(numRows).DataPointLabel .LocationType = VtChLabelLocationTypeCenter .Text = Format(DJData(startingAt + numRows, 1), "m/d/yy") .LineStyle = VtChLabelLineStyleStraight End With SetInfoLabel IIf(startingAt + numRows + 1 > gNumDataRows, gNumDataRows - HScroll1.value, numRows) End Sub Sub Form_Load() Dim numRows%, numCols%, col1Text$, col2Text$ Dim i%, j%, junk& Open App.Path & "\djave.txt" For Input As #1 Input #1, numRows, numCols, col1Text, col2Text ReDim DJData(numRows, numCols) As Double For i = 1 To numRows Input #1, DJData(i, 1), DJData(i, 2) Next i Close #1 '' Size the scrollbar and the chart gNumDataRows = numRows HScroll1.Left = 60 HScroll1.min = 1 HScroll1.max = numRows HScroll1.LargeChange = 20 VtChart1.Left = 60 VtChart1.RowCount = 20 VtChart1.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False VtChart1.Plot.Axis(VtChAxisIdY).Labels.Item(1).Format = "#,##0" ShowView HScroll1.value End Sub Private Sub Form_Resize() VtChart1.Repaint = False lblTitle.Width = ScaleWidth lblInfo.Width = ScaleWidth VtChart1.Width = ScaleWidth - 120 VtChart1.Height = ScaleHeight - HScroll1.Height _ - lblInfo.Height - lblTitle.Height - 210 HScroll1.Width = ScaleWidth - 120 HScroll1.Top = ScaleHeight - HScroll1.Height - 60 VtChart1.Repaint = True End Sub Private Sub HScroll1_Change() '' This prevents the user from scrolling into a dead area '' where a change in scrollbar produces no change in the chart. '' This can happen if the scrollbar is dragged to the end of '' the chart and the user clicks on the arrow towards the '' beginning of the chart. If HScroll1.value + HScroll1.LargeChange > HScroll1.max Then HScroll1.value = HScroll1.max - HScroll1.LargeChange Else ShowView HScroll1.value End If End Sub Private Sub mnuChartType_Click(Index As Integer) Dim i% For i = 0 To 4 mnuChartType(i).Checked = False Next i mnuChartType(Index).Checked = True VtChart1.Plot.SeriesCollection.Item(1).Pen.Width = 2 Select Case Index Case 0 VtChart1.ChartType = VtChChartType2dLine VtChart1.Plot.SeriesCollection.Item(1).Pen.Width = 0 Case 1 VtChart1.ChartType = VtChChartType2dArea Case 2 VtChart1.ChartType = VtChChartType3dLine Case 3 VtChart1.ChartType = VtChChartType3dArea Case 4 VtChart1.ChartType = VtChChartType3dStep End Select End Sub Private Sub mnuSetDaysVisible_Click() Dim title$, msg$, retval$, default$, result$ Let title = "Number of Days in Plot" Let msg = "Enter a number between 10 and " & gNumDataRows default = Str(VtChart1.RowCount) result = InputBox(msg, title, default) While StrComp(result, "") <> 0 And (Val(result) < 10 Or Val(result) > gNumDataRows) MsgBox "Value must be between 10 and " & gNumDataRows result = InputBox(msg, title, default) Wend If StrComp(result, "") <> 0 Then HScroll1.LargeChange = Val(result) ShowView HScroll1.value End If End Sub Private Sub VtChart1_AxisLabelSelected(AxisId As Integer, AxisIndex As Integer, labelSetIndex As Integer, LabelIndex As Integer, MouseFlags As Integer, Cancel As Integer) Cancel = True End Sub Private Sub VtChart1_AxisSelected(AxisId As Integer, AxisIndex As Integer, MouseFlags As Integer, Cancel As Integer) Cancel = True End Sub Private Sub VtChart1_AxisTitleSelected(AxisId As Integer, AxisIndex As Integer, MouseFlags As Integer, Cancel As Integer) Cancel = True End Sub Private Sub VtChart1_ChartSelected(MouseFlags As Integer, Cancel As Integer) Cancel = True End Sub Private Sub VtChart1_FootnoteSelected(MouseFlags As Integer, Cancel As Integer) Cancel = True End Sub Private Sub VtChart1_LegendSelected(MouseFlags As Integer, Cancel As Integer) Cancel = True End Sub Private Sub VtChart1_PlotSelected(MouseFlags As Integer, Cancel As Integer) Cancel = True End Sub Private Sub VtChart1_PointSelected(Series As Integer, DataPoint As Integer, MouseFlags As Integer, Cancel As Integer) SetInfoLabel DataPoint End Sub Private Sub VtChart1_SeriesLabelSelected(Series As Integer, MouseFlags As Integer, Cancel As Integer) Cancel = True End Sub Private Sub VtChart1_TitleSelected(MouseFlags As Integer, Cancel As Integer) Cancel = True End Sub