473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,387 developers and data experts.

Drawing Chart using MSChart Control.

debasisdas
8,127 Expert 4TB
Here's a simple VB6 code snippet that uses the MSChart control to display Charts in VB6.0.
To use this sample, please following steps

Create a new project in VB6
Pull down the Project menu and choose Components .
Select the checkbox next to Microsoft ChartControl 6.0(OLEDB), Click OK.
Add a combobox,one Mschart control and one check box tothe existing form.
Paste in the following code tothe code window
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. 'Fill the combo box with different types of chart types.
  3. With Combo1
  4. .AddItem "3D Bar"
  5. .AddItem "2D Bar"
  6. .AddItem "3D Line"
  7. .AddItem "2D LIne"
  8. .AddItem "3D Area"
  9. .AddItem "2D Area"
  10. .AddItem "3D Step"
  11. .AddItem "2D Step"
  12. .AddItem "3D Combination"
  13. .AddItem "2D Combination"
  14. End With
  15. 'Declare 2D array to store values for the chart
  16. 'Variant ----so that can store both text as well as numbers
  17. Dim X(1 To 7, 1 To 6) As Variant
  18.  
  19. X(1, 2) = "Steel"
  20. X(1, 3) = "Aluminium"
  21. X(1, 4) = "Copper"
  22. X(1, 5) = "Buxite"
  23. X(1, 6) = "Lead"
  24.  
  25. X(2, 1) = "JAN"
  26. X(2, 2) = 2
  27. X(2, 3) = 3
  28. X(2, 4) = 4
  29. X(2, 5) = 5
  30. X(2, 6) = 6
  31.  
  32. X(3, 1) = "FEB"
  33. X(3, 2) = 4
  34. X(3, 3) = 6
  35. X(3, 4) = 3
  36. X(3, 5) = 10
  37. X(3, 6) = 18
  38.  
  39. X(4, 1) = "MAR"
  40. X(4, 2) = 1
  41. X(4, 3) = 3
  42. X(4, 4) = 8
  43. X(4, 5) = 7
  44. X(4, 6) = 9
  45.  
  46. X(5, 1) = "APR"
  47. X(5, 2) = 4
  48. X(5, 3) = 6
  49. X(5, 4) = 13
  50. X(5, 5) = 10
  51. X(5, 6) = 12
  52.  
  53. X(6, 1) = "MAY"
  54. X(6, 2) = 2
  55. X(6, 3) = 9
  56. X(6, 4) = 9
  57. X(6, 5) = 12
  58. X(6, 6) = 7
  59.  
  60. X(7, 1) = "JUN"
  61. X(7, 2) = 13
  62. X(7, 3) = 20
  63. X(7, 4) = 5
  64. X(7, 5) = 18
  65. X(7, 6) = 11
  66. '2D array is the data for the chart control.
  67. MSChart1.ChartData = X
  68. 'Default chart type is se to 2D bar chart.
  69. MSChart1.chartType = 1
  70.  
  71. End Sub
  72.  
  73. Private Sub Check1_Click()
  74. If Check1.Value = 1 Then
  75. 'Show Legends
  76. MSChart1.ShowLegend = True
  77. Check1.Caption = "&Hide Legends"
  78. Else
  79. 'Hide Legends
  80. MSChart1.ShowLegend = False
  81. Check1.Caption = "&Show Legends"
  82. End If
  83. End Sub
  84.  
  85. Private Sub Combo1_Click()
  86. 'To change the chart type at run time.
  87. MSChart1.chartType = Combo1.ListIndex
  88. End Sub
NOTE:-The above sample code works for default name of controls ,code need to be modified accordly if the name of controls are different.
Sep 1 '07 #1
0 50893

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Job Lot | last post by:
How can i dynamically add mschart control to my form. I am getting some "Inavlid state" error. thanx
2
by: Jon Henry | last post by:
Hi, I have a question regarding using the MSChart control in Visual C# Standard 2003. I understand that you can add it to the Toolbox and use it like any other control-- the problem I'm having...
2
by: Don Wash | last post by:
Hi All! I've been searching everywhere for a simple sample of producing a bar graph using CrystalReport by specifying SQL Query, and I've found none of it! I find so many complex samples with so...
0
by: Jeffrey Spoon | last post by:
Hello, I'm trying to plot some data on a 2d line chart using MSChart. The code below worked fine on a 2d bar chart, but nothing appeared when using the 2dline chart property. Should I use the...
0
by: David Caissie | last post by:
I am trying to automate a Vb.net chart using the excel COM object. The problem occurs when trying to run the code in different systems. It is working fine under one of my computers but once i move...
1
debasisdas
by: debasisdas | last post by:
Hi i am using MSCHART control in VB6 to create some interactive chart. It works fine ,but my problem is every time i frame the query dynamically as per user interaction it skips the first record...
1
by: shweta goel | last post by:
Anyone can tell me : how to draw pie chart using MSChart control having data from 2 or 3 variables.
1
by: Arhan Demirali | last post by:
Hello Everyone, I am trying to create an Organizational Chart using C# to display on the WEB. (web application) I have a TABLE of data containing the information for who is the supervisor of...
10
Mas Juliza Alias
by: Mas Juliza Alias | last post by:
I have a table (MSFlexgrid1) in a form (frmCalculate) containing 2 columns of Depth and Volume data. I want to draw a line graph of Depth Vs Volume in a new form (frmGraph) by using MSChart control....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.