Predefined style sheets as well as style sheet configurators use an object called NChartPalette that associates colors to chart elements. When creating a chart palette you can choose from one of the 9 predefined palettes or create your own. The following code snippet loads the predefined “Nevron” palette:
C# |
Copy Code
|
---|---|
NChartPalette palette = new NChartPalette(ChartPredefinedPalette.Nevron);
palette.LabelForeColor = Color.DarkGray;
|
Visual Basic |
Copy Code
|
---|---|
Dim palette As NChartPalette = New NChartPalette() palette.LabelForeColor = Color.DarkGray |
Now you have a palette that differs slightly from the standard “Nevron” palette. To make some use of it you should create a style sheet based on the color entries in the palette. The following code does that:
C# |
Copy Code
|
---|---|
// create palette NChartPalette palette = new NChartPalette(ChartPredefinedPalette.Nevron); palette.LabelForeColor = Color.DarkGray; // build a style sheet based on the palette NFillStyleSheetConfigurator fillConfigurator = new NFillStyleSheetConfigurator(); fillConfigurator.Palette = palette; fillConfigurator.WallFillTemplate = new NGradientFillStyleTemplate(GradientStyle.Horizontal, GradientVariant.Variant1); NStyleSheet sheet = new NStyleSheet(); fillConfigurator.ConfigureSheet(sheet); // apply style sheet to document sheet.Apply(nChartControl1.Document); |
Visual Basic |
Copy Code
|
---|---|
' create palette Dim palette As NChartPalette = New NChartPalette(ChartPredefinedPalette.Nevron) palette.LabelForeColor = Color.DarkGray ' build a style sheet based on the palette Dim fillConfigurator As NFillStyleSheetConfigurator = New NFillStyleSheetConfigurator() fillConfigurator.Palette = palette fillConfigurator.WallFillTemplate = New NGradientFillStyleTemplate(GradientStyle.Horizontal, GradientVariant.Variant1) Dim sheet As NStyleSheet = New NStyleSheet() fillConfigurator.ConfigureSheet(sheet) ' apply style sheet to document sheet.Apply(NChartControl1.Document) |
Now let’s take a closer look at the above code. First we create a palette based on a set of predefined colors – in this case the standard “Nevron” palette, with altered label fore color. Afterwards the code creates a fill style configurator. The configurator uses a palette and a set of fill style templates to create style sheet rules. The above code changes the fill template for walls to gradient, horizontal fill. Finally the fill configurator is used to configure the style sheet and the style sheet is applied on the chart document. The following table lists the colors you can control from the chart palette:
Color Entry | Description |
ControlBackgroundForeColor | Controls the foreground color of the control background. |
ControlBackgroundBackColor | Controls the background color of the control background. |
GaugeBackgroundBackColor | Controls the foreground color of gauges background. |
GaugeBackgroundForeColor | Controls the background color of gauges background. |
LabelForeColor | Controls the foreground color of labels. |
LabelBackColor | Controls the background color of labels. |
WallForeColor | Controls the foreground color of chart walls. |
WallBackColor |
Controls the background color of chart walls. |
IndicatorForeColor | Controls the foreground color of gauge indicators. |
IndicatorBackColor | Controls the background color of gauge indicators. |
RulerStrokeColor | Controls the color of the stroke style applied to axis rulers. |
TickStrokeColor | Control the color of the stroke style applied to ticks. |
GridStrokeColor | Controls the color of the stroke style applied to axis grid lines. |
SeriesColors | Controls the color of series data items, or series within a chart. |