Jun 11, 2009

Charts with Power WebPart ( Management-Eye-Catchers )

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

image

image

Setup and Configuration:

  1. 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. 2. Download and install Power WebPart (follow the instructions in the readme.txt)
  3. 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:


ChartImgCACU0PM6 ChartImgCAEO5EDD Bollinger2



The limitation is your imagination!

Jun 10, 2009

SPoshMod v1.0 Released!

I'm glad to annouce that SPoshMod V1.0 has been released today. SPoshMod is a PowerShell 2.0 Module for SharePoint wrapping the most common SharePoint object model calls (e.g. Get-SPWeb, Get-SPSite...).

SPoshMod is a joint project from Eric Kraus (founder) and me. If you have written a helpful script or function and think it would be useful in the module, please send them to sposhmod@live.com we will give credit to you in the module.

More coming soon...

Jun 8, 2009

Using SharePoint Controls with Power WebPart

SharePoint comes with a bunch of custom ASP.NET Controls. For sure you can use them with Power WebPart.
This example shows how you can search for list items by title containing a specified search string and display the result in a SharePoint list view, featuring the SharePoint ListViewByQuery control.
image

The Script

$textBox = New-Object System.Web.UI.WebControls.TextBox;
$button = New-Object System.Web.UI.WebControls.Button;
$button.Text = "Search"
$listView = New-Object Microsoft.SharePoint.WebControls.ListViewByQuery;
$br = New-Object System.Web.UI.WebControls.WebControl([System.Web.UI.HtmlTextWriterTag]::Br)

function createchildcontrols($controls)
{
$controls.Add($textBox)
$controls.Add($button)
$controls.Add($br)
$controls.Add($listView)
}

function onprerender()
{
# Parameter 1 can be configured in the webpart editor
$listTitle = $webpart.Parameter1

$list = $web.Lists[$listTitle]
$listView.List = $list;
$query = New-Object Microsoft.SharePoint.SPQuery -ArgumentList $list.DefaultView;

$query.Query = "
                                 


$($textBox.Text)

"

$listView.Query = $query
$listView.DisableFilter = $true
$listView.DisableSort = $true 
}

function onerror($writer)
{
$writer.Write("List title is not configured or the list does not exist.")
}