Applies to: Nevron Chart for SharePoint (WSS3.0, SharePoint 2007/2010/2013)
How to set custom color and zone range for the Grid Surface Chart WebPart?
Nevron Chart for SharePoint provides support for plotting Grid Surface Charts. The surface coloring is controlled by the following properties in the Chart Web Part Designer:
- Palette Mode - defines the mode in which the surface zoning palette is determined. Possible values are:
- Sync With Axis Scale - the palette is automatically synchronized with axis scale.
- Custom Steps Count - the palette is automatically calibrated to the elevation data [min:max] range, but has the number of steps defined by the Palette Steps setting.
- Palette Steps - defines the number of steps in the palette when the Palette Mode is set to Custom Steps Count.
However, you may need to configure custom color and zone range for your Grid Surface. You can achieve this by using custom code injection in the Code tab of the Chart Web Part Designer.
The following code will modify the standard colors and the zone range:
[C#]
using
System;
using
System.Drawing;
using
Nevron.GraphicsCore;
using
Nevron.Chart;
using
Nevron.ReportingServices;
namespace
MyNamespace
{
/// <summary>
/// Sample class
/// </summary>
public
class
MyClass
{
/// <summary>
/// Main entry point
/// </summary>
/// <param name="context"></param>
public
static
void
RSMain(NRSChartCodeContext context)
{
if
(context.Document.Charts.Count == 0)
return
;
// get the first chart in the document
NChart chart = context.Document.Charts[0];
if
(chart.Series.Count == 0)
return
;
NGridSurfaceSeries surface = chart.Series[0]
as
NGridSurfaceSeries;
if
(surface ==
null
)
return
;
// setup a custom palette
surface.AutomaticPalette =
false
;
surface.Palette.Clear();
surface.Palette.Add(100, Color.FromArgb(255, 121, 0));
surface.Palette.Add(13.5, Color.FromArgb(255, 126, 0));
surface.Palette.Add(12.0, Color.FromArgb(255, 180, 107));
surface.Palette.Add(10.5, Color.FromArgb(255, 187, 120));
surface.Palette.Add(9.0, Color.FromArgb(255, 190, 126));
surface.Palette.Add(7.5, Color.FromArgb(255, 211, 168));
surface.Palette.Add(6.0, Color.FromArgb(255, 228, 206));
surface.Palette.Add(5.0, Color.FromArgb(255, 239, 230));
surface.Palette.Add(4.5, Color.FromArgb(255, 249, 253));
surface.Palette.Add(2.5, Color.FromArgb(228, 234, 255));
surface.Palette.Add(0.0, Color.FromArgb(168, 197, 255));
}
}
}
[VB.NET]
Imports
System
Imports
System.Drawing
Imports
Nevron.GraphicsCore
Imports
Nevron.Chart
Imports
Nevron.ReportingServices
Namespace
MyNamespace
''' <summary>
''' Sample class
''' </summary>
Public
Class
[
MyClass
]
''' <summary>
''' Main entry point
''' </summary>
''' <param name="context"></param>
Public
Shared
Sub
RSMain(context
As
NRSChartCodeContext)
If
context.Document.Charts.Count = 0
Then
Return
End
If
' get the first chart in the document
Dim
chart
As
NChart = context.Document.Charts(0)
If
chart.Series.Count = 0
Then
Return
End
If
Dim
surface
As
NGridSurfaceSeries = TryCast(chart.Series(0), NGridSurfaceSeries)
If
surface
Is
Nothing
Then
Return
End
If
' setup a custom palette
surface.AutomaticPalette =
False
surface.Palette.Clear()
surface.Palette.Add(100, Color.FromArgb(255, 121, 0))
surface.Palette.Add(13.5, Color.FromArgb(255, 126, 0))
surface.Palette.Add(12.0, Color.FromArgb(255, 180, 107))
surface.Palette.Add(10.5, Color.FromArgb(255, 187, 120))
surface.Palette.Add(9.0, Color.FromArgb(255, 190, 126))
surface.Palette.Add(7.5, Color.FromArgb(255, 211, 168))
surface.Palette.Add(6.0, Color.FromArgb(255, 228, 206))
surface.Palette.Add(5.0, Color.FromArgb(255, 239, 230))
surface.Palette.Add(4.5, Color.FromArgb(255, 249, 253))
surface.Palette.Add(2.5, Color.FromArgb(228, 234, 255))
surface.Palette.Add(0.0, Color.FromArgb(168, 197, 255))
End
Sub
End
Class
End
Namespace
Article ID: 229, Created On: 12/6/2012, Modified: 1/29/2013