Microsoft KB Archive/192902

= How To Change Colors to Patterns with the MSChart Control =

Article ID: 192902

Article Last Modified on 6/29/2004

-

APPLIES TO


 * 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

-



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
 Create a new Standard EXE project in Visual Basic. Form1 is created by default. Choose Components from the Project menu to show the Components Dialog. In Visual Basic 5.0, select "Microsoft Chart Control." In Visual Basic 6.0, select "Microsoft Chart Control 6.0 (OLEDB)." Place an instance of the Chart control and a CommandButton on Form1.  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  Run the project and click Command1 and note that the chart now uses monochrome patterns instead of colors.</ol>

<div class="references_section">