Applies to: Nevron Chart for SharePoint (WSS3.0, SharePoint 2007/2010/2013)
How to make Pie Chart slices detached (explode) in the Chart for SharePoint?
In Nevron Chart for SharePoint, you can control the Pie Chart slice detachment via code injection, through the chart web part designer Code tab.
Use the following code in the Code tab of the Chart designer to programmatically configure the Pie Chart slices detachment:
[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)
{
NPieChart pieChart = context.Document.Charts[0]
as
NPieChart;
if
(pieChart ==
null
)
return
;
for
(
int
i = 0; i < pieChart.Series.Count; i++)
{
NPieSeries pieSeries = (NPieSeries)pieChart.Series[i];
// explode all pie slices
for
(
int
j = 0; j < pieSeries.Values.Count; j++)
{
pieSeries.Detachments.Add(2);
}
}
}
}
}
[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)
Dim
pieChart
As
NPieChart = TryCast(context.Document.Charts(0), NPieChart)
If
pieChart
Is
Nothing
Then
Return
End
If
For
i
As
Integer
= 0
To
pieChart.Series.Count - 1
Dim
pieSeries
As
NPieSeries =
DirectCast
(pieChart.Series(i), NPieSeries)
' explode all pie slices
For
j
As
Integer
= 0
To
pieSeries.Values.Count - 1
pieSeries.Detachments.Add(2)
Next
Next
End
Sub
End
Class
End
Namespace
The following code will detach (explode) only the biggest and the smallest slices of the Pie Chart:
[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)
{
NPieChart pieChart = context.Document.Charts[0]
as
NPieChart;
if
(pieChart ==
null
)
return
;
for
(
int
i = 0; i < pieChart.Series.Count; i++)
{
NPieSeries pieSeries = (NPieSeries)pieChart.Series[i];
// set all detachments to 0
pieSeries.Detachments.Clear();
for
(
int
j = 0; j < pieSeries.Values.Count; j++)
{
pieSeries.Detachments.Add(0.0);
}
// explode biggest pie slice
int
nIndex = pieSeries.Values.FindMaxValue();
if
(nIndex != -1)
{
pieSeries.Detachments[nIndex] = 3.0f;
}
// explode smallest value
nIndex = pieSeries.Values.FindMinValue();
if
(nIndex != -1)
{
pieSeries.Detachments[nIndex] = 5.0f;
}
}
}
}
}
[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)
Dim
pieChart
As
NPieChart = TryCast(context.Document.Charts(0), NPieChart)
If
pieChart
Is
Nothing
Then
Return
End
If
For
i
As
Integer
= 0
To
pieChart.Series.Count - 1
Dim
pieSeries
As
NPieSeries =
DirectCast
(pieChart.Series(i), NPieSeries)
' set all detachments to 0
pieSeries.Detachments.Clear()
For
j
As
Integer
= 0
To
pieSeries.Values.Count - 1
pieSeries.Detachments.Add(0.0)
Next
' explode biggest pie slice
Dim
nIndex
As
Integer
= pieSeries.Values.FindMaxValue()
If
nIndex <> -1
Then
pieSeries.Detachments(nIndex) = 3F
End
If
' explode smallest value
nIndex = pieSeries.Values.FindMinValue()
If
nIndex <> -1
Then
pieSeries.Detachments(nIndex) = 5F
End
If
Next
End
Sub
End
Class
End
Namespace
Article ID: 173, Created On: 1/31/2011, Modified: 1/29/2013