Thursday, June 28, 2018

Chart design with special feature in Visual Basic 6.0

Chart design with special feature in Visual Basic 6.0

In this post, there is description about chart design with special feature in Visual Basic 6.0 with easy tech tips. There is requirement of graphical description of data, where we display data with graph presentation. A developer need predefined tools or have to create a tools to describe the graphical presentation.


In Visual Basic 6.0, provide a predefined chart control tools with name “Microsoft Chart Control 6.0(OLEDB)” name. If you cannot find this component in component window, download “MSChart20.ocx" for any website where this component available. And put this OCX file in “C\Windows\System32” path.

 Where to find Chart Control?
For add it in Visual Basic 6.0, you have to go to “Project” menu of your Application window. And find “Component” option and click on it.

Then a window will open, find “Microsoft Chart Control 6.0(OLEDB)” and check on it. Then press “Apply” and “OK” button.

Steps:
“Project”>> “Component”>> “Microsoft Chart Control 6.0(OLEDB)” (check it)

Add Chart Control To ToolBox for design
Add Control To ToolBox Process
This will add on ToolBox with MSChart MSChart Icon in VB6.0icon.

 What types of Properties use for Chart Design?
Here, we will learn some properties of MSChart Control through “Properties” window or through code. There are some following properties instructions.
 (1) Change Chart Type Properties:
For this setting, you have to go to “Properties” window and find “ChartType” property. Select any option whatever you want.
Chart type properties settings for design
Chart type properties settings
You can change it through coding. Suppose, you want to change chart type through combo selection. Then you have to write code in Combo’s Change() event. There is following code process.
Private Sub Combo2_Change()
  Dim Chrttype As String
  Chrttype = Combo2.Text

  With MSChart1
    Select Case Chrttype

     Case "2dArea"
       .chartType = VtChChartType2dArea

     Case "2dBar"
       .chartType = VtChChartType2dBar

     Case "2dCombination"
       .chartType = VtChChartType2dCombination

     Case "2dLine"
       .chartType = VtChChartType2dLine

     Case "2dPie"
       .chartType = VtChChartType2dPie

     Case "2dStep"
       .chartType = VtChChartType2dStep

     Case "2dXY"
       .chartType = VtChChartType2dXY

     Case "3dArea"
       .chartType = VtChChartType3dArea

     Case "3dBar"
       .chartType = VtChChartType3dBar

     Case "3dCombination"
       .chartType = VtChChartType3dCombination

     Case "3dLine"
       .chartType = VtChChartType3dLine

     Case "3dStep"
       .chartType = VtChChartType3dStep

    End Select
  End With

End Sub
You have to write this code in Combo’s Click() event.
Chart type design output in VB6


 (2) Change Graph Border’s Style with Shadow:
You can Change Graph’s border through MSChart’s Custom Property window. Just right click on MSChart1 and select “Properties” Option. This will show “Property Pages” screen. This screen contains multiple tabs. Go to “Backdrop” tab and select “Plot” option from “Property Name” combo. And apply settings whatever you want to change.

Steps:
MSChart1 (Right Click)>> Properties >> Backdrop >> Plot

Chart design with plot color settings
Chart's Plot setting
If you want to change border style at run time, then you have to right code for it, Suppose, you want to change it through button press. Then write this code on command Click() event as mention bellow.
Border Style Code:
Private Sub Command2_Click()

   'This will change border type
   MSChart1.Plot.Backdrop.Frame.Style = VtFrameStyleThickOuter

   'This will change Border color
   MSChart1.Plot.Backdrop.Frame.FrameColor.Set 255, 100, 20

End Sub
Graph Shadow Code:
Private Sub Command1_Click()

   MSChart1.Plot.Backdrop.Shadow.Style = VtShadowStyleDrop

End Sub
Graph with border and shadow output

 (3) Change Graph Color:
If you want to change Graph color according to your desire, then there is two processes, first is through property setting and second is through code.

Color setting through Property:
Just go to Custom property page window and select “Series Color” Tab. Then apply C1, C2, C3, C4 etc. color settings.
Series Color settings for chart design
Series Color settings
After that you will see that this will change the color of your graph.


Color setting through Code: 
Suppose, you want to change color at run time, then write code inside command’s Click() event as mention bellow.
Private Sub Command4_Click()
  With MSChart1
     'C1 Color change
     .Plot.SeriesCollection(1).DataPoints(-1).Brush.FillColor.Set 152, 50, 250

     'C2 Color Change
     .Plot.SeriesCollection(2).DataPoints(-1).Brush.FillColor.Set 252, 50, 100

     'C3 Color Change
     .Plot.SeriesCollection(3).DataPoints(-1).Brush.FillColor.Set 12, 250, 200

     'C2 Color Change
     .Plot.SeriesCollection(4).DataPoints(-1).Brush.FillColor.Set 252, 150, 80
  End With
End Sub
Graph with plot color output

 (4) Change Graph Brush Style:
Now, if you want to change brush style around graph, you have to write code for setting of it. Suppose, if you want to change through combo selection, then write code inside Combo’s Change() and Click() event. The code is describing bellow.
Private Sub Combo1_Change()

  With MSChart1

     If Combo1.Text = "Null" Then
        .Plot.Wall.Brush.Style = VtBrushStyleNull
     End If

     If Combo1.Text = "Solid" Then
        .Plot.Wall.Brush.Style = VtBrushStyleSolid
     End If

     If Combo1.Text = "Pattern" Then
        .Plot.Wall.Brush.Style = VtBrushStylePattern
     End If

     If Combo1.Text = "Hatched" Then
        .Plot.Wall.Brush.Style = VtBrushStyleHatched
     End If

  End With

End Sub
This code’s process is mention in following Gif.
Graph with brush style Output
Now, there is some features description mention above by which, you can easily learn chart design with special feature in Visual Basic 6.0 with SKOTechLearn.

0 comments: