Each series derived from Series has an associated instance of an Appearance object controlling the filling and lines of the data points displayed by the series. It is accessible with the help of the Appearance property of the Series class.
VB.NET |
|
Dim appearance As Appearance = series.Appearance |
C# |
|
Appearance appearance = series.Appearance; |
Controlling the Data Point Fill Effects
The filling mode of the data points is controlled by the FillMode property of the Appearance class. It is of type AppearanceFillMode and accepts the following values (for details, see AppearanceFillMode Enumeration):
Series
DataPoints
Predefined
By default it is set to Series. The following is a description of these modes:
- Series Mode (default setting): By default, data points are displayed with a uniform fill effect, which is controlled by series-specific properties. For example, a bar chart is displayed with the fill effect specified by the BarFillEffect property, while pie segments are filled with the filling described by the fill effect accessible through the PieFillEffect property. In this case, helper routines for feeding data that do not require fill effect can be used. For example:
VB.NET |
|
[Visual Basic] bar.Add("10") bar.Add("20") bar.Add("40") bar.BarFillEffect.SetSolidColor(Color.Green) ' make all bars green
|
C# |
|
bar.Add("10"); bar.Add("20"); bar.Add("40"); bar.BarFillEffect.SetSolidColor(Color.Green); // make all bars green
|
The series can also implement some built-in logic and use the filling of the data points to express it. This is the case of the Stock chart (see Stock Candle and Stock Stick), which paints the data points with user specified up and down fill effects (controlled by the UpFillEffect and DownFillEffect properties of the Stock Series object).
- DataPoints Mode: In this mode, the fill effects of the data points are contained in a data series of fill effects accessible through the FillEffects property of the Appearance object. If the count of the fill effects in the data series is smaller than the data point count, the control will cycle through the available fill effects. If the fill effects data series is empty, a default fill effect will be used. For example, the following code will add two fill effects:
VB.NET |
|
bar.Appearace.FillEffects.Add(New FillEffect(Color.Red)) bar.Appearace.FillEffects.Add(New FillEffect(Color.Blue))
|
C# |
|
bar.Appearace.FillEffects.Add(new FillEffect(Color.Red)); bar.Appearace.FillEffects.Add(new FillEffect(Color.Blue));
|
and switch the Appearance fill mode to DataPoints:
VB.NET |
|
bar.Appearance.FillMode = AppearanceFillMode.DataPoints
|
C# |
|
bar.Appearance.FillMode = AppearanceFillMode.DataPoints;
|
In the context of the code in point 1, the first bar will be painted in red, the second in blue, and the third again in red. If you want to display the third bar in green, you simply have to add another fill effect:
VB.NET |
|
bar.Appearace.FillEffects.Add(New FillEffect(Color.Green))
|
C# |
|
bar.Appearace.FillEffects.Add(new FillEffect(Color.Green));
|
When a series filling appearance is defined in cycle mode, it is a good idea to use the series helper routines that require a FillEffect object. The following sample code will create a pie chart with different pie colors.
VB.NET |
|
Dim pie As PieSeries = CType(Chart.Series, PieSeries) Dim pie As PieSeries = CType(Chart.Series.Add(SeriesType.Pie), PieSeries) pie.Appearance.FillMode = AppearanceFillMode.Cycle pie.Add(12,"Apples",New FillEffect(Color.Red)) pie.Add(34,"Oranges",New FillEffect(Color.Green)) pie.Add(26,"Bananas",New FillEffect(Color.Blue))
|
C# |
|
PieSeries pie = (PieSeries)Chart.Series; PieSeries pie = (PieSeries)Chart.Series.Add(SeriesType.Pie); pie.Appearance.FillMode = AppearanceFillMode.Cycle; pie.Add(12, "Apples", new FillEffect(Color.Red)); pie.Add(34, "Oranges", new FillEffect(Color.Green)); pie.Add(26, "Bananas", new FillEffect(Color.Blue));
|
- Predefined Mode: In this mode, the control uses predefined colors for the filling of the data points. No user action is required: this can be useful if you just want to display your data points in different colors, but do not want to bother to specify them exactly. The following code creates a bar chart with different bar colors.
VB.NET |
|
Dim bar As BarSeries = CType(Chart.Series.Add(SeriesType.Bar), BarSeries) bar.Appearance.FillMode = AppearanceFillMode.Predefined pie.Add(12) pie.Add(34) pie.Add(26)
|
C# |
|
BarSeries bar = (BarSeries)Chart.Series.Add(SeriesType.Bar); bar.Appearance.FillMode = AppearanceFillMode.Predefined; pie.Add(12); pie.Add(34); pie.Add(26);
|
Controlling the Data Point Line Properties
Data point line properties are analogously controlled by the LineMode property of the Appearance class. It is of type AppearanceLineMode and accepts the following values (for details, see AppearanceLineMode Enumeration):
Series
DataPoints
Predefined
The Control
The control implements the exact same logic to determine the line properties as is used for a particular data point. When LineMode is set to DataPoints, the LineProperties objects are extracted from a data series containing LineProperties objects, which is accessible from the LineProperties property of the Appearance object.
Related Examples
Windows Forms: Series Attributes\Appearance
See Also
Series | Appearance