Applies to: Nevron Chart for Reporting Services (SSRS 2005 and 2008)
How to make Pie Chart slices detached (explode) in the Chart for SQL Reporting Services?
In Nevron Chart for SQL Server Reporting Services, you can control the Pie Chart slice detachment via code injection, through the chart editor Code tab.
Use the following code in the Code tab of the Chart editor 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);
}
}
}
}
}
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;
}
}
}
}
}
Article ID: 174, Created On: 1/31/2011, Modified: 7/18/2011