VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Creating a Microsoft Chart Control Demo

by Bhuwan Chand Joshi (69 Submissions)
Category: Graphics
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 21st July 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Creating a Microsoft Chart Control Demo

Rate Creating a Microsoft Chart Control Demo



'Place Micrsoft Chart Control on the form
'Place Timer Control on the form
'Place Combobox Control on the form
'Make a reference to Microsoft Excel 8.0 Object Library

Private Sub Combo1_Click()

On Error GoTo Err_Handler

MSChart1.Visible = False
ProgressBar1.Visible = True
Timer1.Enabled = True

If Combo1.Text = "2dArea" Then
    MSChart1.ChartType = VtChChartType2dArea
    ElseIf Combo1.Text = "2dLine" Then
    MSChart1.ChartType = VtChChartType2dLine
    ElseIf Combo1.Text = "2dPie" Then
    MSChart1.ChartType = VtChChartType2dPie
    ElseIf Combo1.Text = "2dXY" Then
    MSChart1.ChartType = VtChChartType2dXY
    ElseIf Combo1.Text = "2dBar" Then
    MSChart1.ChartType = VtChChartType2dBar
    ElseIf Combo1.Text = "2dStep" Then
    MSChart1.ChartType = VtChChartType2dStep
    ElseIf Combo1.Text = "3dBar" Then
    MSChart1.ChartType = VtChChartType3dBar
    ElseIf Combo1.Text = "3dArea" Then
    MSChart1.ChartType = VtChChartType3dArea
    ElseIf Combo1.Text = "3dLine" Then
    MSChart1.ChartType = VtChChartType3dLine
    ElseIf Combo1.Text = "3dCombination" Then
    MSChart1.ChartType = VtChChartType3dCombination
End If

Dim xlApp As Excel.Application
Set xlApp = New Excel.Application
Dim xlWkb As Excel.Workbook
Set xlWkb = xlApp.Workbooks.Open("E:\MSChart\MSChart.xls") ' Data Source
Dim xlSht As Excel.Worksheet
Set xlSht = xlWkb.Worksheets(1)

Dim arrPlotData(1 To 5, 1 To 2)

For I = 1 To 5

arrPlotData(I, 1) = xlSht.Range("A" & I + 1).Value
arrPlotData(I, 2) = xlSht.Range("B" & I + 1).Value

Next I

MSChart1.ChartData = arrPlotData
MSChart1.Title = "Microsoft Chart Control Demo"

xlApp.Quit
Set xlApp = Nothing

Err_Handler:
      Err.Clear

End Sub

Private Sub Form_Load()

On Error GoTo Err_Handler

Form1.BorderStyle = 1
ProgressBar1.Visible = False
Timer1.Interval = 25
ProgressBar1.Max = 50

Combo1.AddItem "2dArea"
Combo1.AddItem "2dLine"
Combo1.AddItem "2dPie"
Combo1.AddItem "2dXY"
Combo1.AddItem "2dBar"
Combo1.AddItem "2dStep"
Combo1.AddItem "3dBar"
Combo1.AddItem "3dArea"
Combo1.AddItem "3dLine"
Combo1.AddItem "3dCombination"

Combo1.ListIndex = 4

Err_Handler:
    Err.Clear

End Sub

Private Sub Timer1_Timer()

Static intTime

   If IsEmpty(intTime) Then intTime = 1
   
   ProgressBar1.Value = intTime
       
   If intTime = ProgressBar1.Max Then
      Timer1.Enabled = False
      ProgressBar1.Visible = False
      MSChart1.Visible = True
      intTime = 1
      ProgressBar1.Value = ProgressBar1.Min
   Else
      intTime = intTime + 1
   End If

End Sub


Download this snippet    Add to My Saved Code

Creating a Microsoft Chart Control Demo Comments

No comments have been posted about Creating a Microsoft Chart Control Demo. Why not be the first to post a comment about Creating a Microsoft Chart Control Demo.

Post your comment

Subject:
Message:
0/1000 characters