How To Change Colors to Patterns with the MSChart Control (192902)



The information in this article applies to:

  • Microsoft Visual Basic Learning Edition for Windows 5.0
  • Microsoft Visual Basic Learning Edition for Windows 6.0
  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

This article was previously published under Q192902

SUMMARY

By default, the MSChart control uses colors to differentiate between data sets. This works well on a color monitor or printer, but if a printout to a monochrome printer is created, the colors may be hard to distinguish. Using the code provided, you can programmatically change the MSChart control to use patterns instead of colors.

MORE INFORMATION

Modifying some properties is all that needs to be done to get the MSChart control to use patterns.

Step-by-Step Example

  1. Create a new Standard EXE project in Visual Basic. Form1 is created by default.
  2. Choose Components from the Project menu to show the Components Dialog.
  3. In Visual Basic 5.0, select "Microsoft Chart Control." In Visual Basic 6.0, select "Microsoft Chart Control 6.0 (OLEDB)."
  4. Place an instance of the Chart control and a CommandButton on Form1.
  5. Place the following code in the General Declaration Section of Form1:
         Private Sub Command1_Click()
         MSChart1.Plot.SeriesCollection(1).DataPoints(-1).Brush.Style _
            = VtBrushStylePattern
         MSChart1.Plot.SeriesCollection(1).DataPoints(-1).Brush.Index _
            = VtBrushPatternBoldDownDiagonal
         MSChart1.Plot.SeriesCollection(1).DataPoints(-1).Brush.FillColor.Set _
            255, 255, 255
    
         MSChart1.Plot.SeriesCollection(2).DataPoints(-1).Brush.Style _
            = VtBrushStylePattern
         MSChart1.Plot.SeriesCollection(2).DataPoints(-1).Brush.Index _
            = VtBrushPatternBoldHorizontal
         MSChart1.Plot.SeriesCollection(2).DataPoints(-1).Brush.FillColor.Set _
            255, 255, 255
    
         MSChart1.Plot.SeriesCollection(3).DataPoints(-1).Brush.Style _
            = VtBrushStylePattern
         MSChart1.Plot.SeriesCollection(3).DataPoints(-1).Brush.Index _
            = VtBrushPatternBoldUpDiagonal
         MSChart1.Plot.SeriesCollection(3).DataPoints(-1).Brush.FillColor.Set _
            255, 255, 255
    
         MSChart1.Plot.SeriesCollection(4).DataPoints(-1).Brush.Style _
            = VtBrushStylePattern
         MSChart1.Plot.SeriesCollection(4).DataPoints(-1).Brush.Index _
            = VtBrushPatternBoldVertical
         MSChart1.Plot.SeriesCollection(4).DataPoints(-1).Brush.FillColor.Set _
            255, 255, 255
         End Sub
    					
  6. Run the project and click Command1 and note that the chart now uses monochrome patterns instead of colors.

REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base:

168749 How To Print the Contents of the MS Chart Control


Modification Type:MinorLast Reviewed:6/29/2004
Keywords:kbCtrl kbhowto KB192902