In this post I’ll give you some ideas how you can script charts in SharePoint with Power WebPart featuring Microsoft Chart Controls.
Visualizing a SharePoint list as a pie
Setup and Configuration:
- 1. Download and install Microsoft Chart Controls (ensure that System.Web.DataVisualization.dll is either in the GAC or in the web app’s bin folder)
- 2. Download and install Power WebPart (follow the instructions in the readme.txt)
- 3. To use the Chart Controls in ASP.NET or SharePoint you have to modify the web.config:
Add this line to appSettings section:
<add key="ChartImageHandler" value="Storage=session;Timeout=20;" />
Add this line to the httpHandlers section:
<add path="ChartImg.axd" verb="GET,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
The Script
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.DataVisualization")
$chart = New-Object System.Web.UI.DataVisualization.Charting.Chart
$series = new-object System.Web.UI.DataVisualization.Charting.Series
$chartArea = New-Object System.Web.UI.DataVisualization.Charting.ChartArea
$legend = New-Object System.Web.UI.DataVisualization.Charting.Legend
function createchildcontrols($controls)
{
$data = $web.Lists["Chart"].Items.GetDataTable()
$chart.DataSource = $data
$chart.Width=500
$series.ChartType = [System.Web.UI.DataVisualization.Charting.SeriesChartType]::Pie
$series.XValueMember ="Title"
$series.YValueMembers ="Value"
$series.ShadowOffset = 2
$series.IsValueShownAsLabel = $true
$chart.Series.Add($series)
$chartArea.Area3DStyle.Enable3D = $true
$chart.ChartAreas.Add($chartArea)
$chart.Legends.Add($legend)
$controls.Add($chart)
$chart.DataBind()
$series.Points.FindMaxByValue()["Exploded"] = $true
}This just one example! The Chart Control is really mighty! Download the chart control examples from Microsoft to get an impression:
The limitation is your imagination!