How To Set a Custom Range for Value Axis with MSChart Control
This article was previously published under Q189159
This article has been archived. It is offered "as is" and will no longer be updated.
When plotting points with the Microsoft Chart control, the scale for thevalue axis is scaled to represent only the range of numbers needed todisplay the data points being charted. For example, if the data points youare charting are between 1000 and 1010, the full range of 0 through 1010 isnot needed and may not be used.
At times it may be desirable or necessary to specify a custom range for thevalue axis. Microsoft Chart offers properties that allow the user tocustomize this setting. To set a custom range, three properties must beset: Auto, Minimum, and Maximum. Below are the steps to create a sampleapplication that demonstrates how to configure the chart's scaleprogrammatically.
- Open a new Standard EXE project. Form1 is created by default.
- Choose Components from the Project menu, and add a reference to "Microsoft Chart Control."
- Add a Chart control to Form1 (sample data is automatically supplied).
- Add a CommandButton to Form1.
- Paste the following code into Form1's code module:
Private Sub Command1_Click() ' Set chart type to 2d bar Form1.MSChart1.chartType = VtChChartType2dBar ' Use manual scale to display y axis (value axis) With Form1.MSChart1.Plot.Axis(VtChAxisIdY).ValueScale .Auto = False .Minimum = -100 .Maximum = 100 End With End Sub
- Run the sample project.
- Note that the range of the Y axis is 0 to 100.
- Click the CommandButton.
- Note that the range of the Y axis now reflects the -100 to 100 range that was set programmatically.
kbDSupport kbDSD size graph kbVBp kbVBp500 kbCtrl kbVBp600
Article ID: 189159 - Last Review: 12/05/2015 08:55:03 - Revision: 3.1
Microsoft Visual Basic 5.0 Learning Edition, Microsoft Visual Basic 6.0 Learning Edition, Microsoft Visual Basic 5.0 Professional Edition, Microsoft Visual Basic 6.0 Professional Edition, Microsoft Visual Basic 5.0 Enterprise Edition, Microsoft Visual Basic 6.0 Enterprise Edition
- kbnosurvey kbarchive kbhowto KB189159