<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>A Developer&#039;s Blog &#187; Charting</title>
	<atom:link href="http://blog.hoegaerden.be/tag/charting/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hoegaerden.be</link>
	<description>SQL Server, BI, .NET, IT and anything else I have been playing with.</description>
	<lastBuildDate>Wed, 01 Sep 2010 06:27:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Pie Chart Techniques</title>
		<link>http://blog.hoegaerden.be/2009/10/25/pie-chart-techniques/</link>
		<comments>http://blog.hoegaerden.be/2009/10/25/pie-chart-techniques/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 13:26:55 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[Charting]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Reporting Services 2008]]></category>
		<category><![CDATA[SSRS]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2009/10/25/pie-chart-techniques/</guid>
		<description><![CDATA[A while ago I wrote an article called Chart Optimization Tips.&#160; This article explained how to optimize a Column Chart.&#160; Today I have returned to show you some Pie Chart implementation techniques.
As usual, I will be using the AdventureWorks2008 database, available at CodePlex.&#160; The chart itself will be implemented using SQL Server 2008 Reporting Services.
Retrieving [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I wrote an article called <a title="Chart Optimization Tips" href="http://blog.hoegaerden.be/2009/07/20/chart-optimization-tips/" target="_blank">Chart Optimization Tips</a>.&#160; This article explained how to optimize a Column Chart.&#160; Today I have returned to show you some Pie Chart implementation techniques.</p>
<p>As usual, I will be using the AdventureWorks2008 database, available at <a title="SQL Server sample databases at CodePlex" href="http://www.codeplex.com/MSFTDBProdSamples" target="_blank">CodePlex</a>.&#160; The chart itself will be implemented using SQL Server 2008 Reporting Services.</p>
<h2>Retrieving The Data</h2>
<p>The dataset in our report uses the following query:</p>
<pre class="code"><span style="color: blue">select </span>SWD<span style="color: gray">.*, </span>SWA<span style="color: gray">.</span>City<span style="color: gray">, </span>SWA<span style="color: gray">.</span>StateProvinceName<span style="color: gray">,
    </span>SWA<span style="color: gray">.</span>PostalCode<span style="color: gray">, </span>SWA<span style="color: gray">.</span>CountryRegionName<span style="color: gray">, </span>SWA<span style="color: gray">.</span>AddressType
<span style="color: blue">from </span>Sales<span style="color: gray">.</span>vStoreWithDemographics SWD
<span style="color: gray">inner join </span>Sales<span style="color: gray">.</span>vStoreWithAddresses SWA
    <span style="color: blue">on </span>SWA<span style="color: gray">.</span>BusinessEntityID <span style="color: gray">= </span>SWD<span style="color: gray">.</span>BusinessEntityID</pre>
<p>This query illustrates a bad coding practice: never use “SELECT *”.&#160; Ideally you should only retrieve the columns that you need for the report.&#160; That will optimize performance when generating the report.&#160; But that is not the goal of this article so I’ll leave the query as it is.</p>
<h2>A Basic Pie Chart</h2>
<p>To get started with our Pie Chart I have selected the third icon in the list of Shape charts.&#160; This adds a regular 3D pie chart to the report.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image78.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Select Chart Type window" border="0" alt="Select Chart Type window" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb5.png" width="546" height="489" /></a></p>
<p>To set up the chart I dragged AnnualSales from the Report Data pane into the “Drop data fields here” area and StateProvinceName into the “Drop category fields here”.</p>
<p>In case you don’t see the Report Data view (it has a tendency to disappear now and then), you can open it through the main menu: View &gt; Report Data.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Report Data Pane" border="0" alt="Report Data Pane" src="http://blog.hoegaerden.be/wp-content/uploads/image79.png" width="290" height="450" /></p>
<p>This is what our report looks like in Preview:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image80.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Basic Pie Chart" border="0" alt="Basic Pie Chart" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb6.png" width="551" height="367" /></a></p>
<p>Wow, we’ve still got some work to do, this looks like a kids color book!&#160; You wouldn’t say that this chart is showing the annual sales, would you?&#160; There aren’t even any numbers on it!&#160; Let’s get started on improving this.</p>
<h2>Sorting The Numbers</h2>
<p>A good implementation practice is to sort the slices from large to small.&#160; If the slices are not sorted, it’s difficult to tell which state is performing better than another.&#160; Just take a look at the previous image and compare the following two slices:</p>
<ul>
<li>the pie shown in grey at 12:00 </li>
<li>the pie shown in yellow at 03:00 </li>
</ul>
<p>Which one is the larger of the two?&#160; Indeed, “I don’t know” is the right answer.</p>
<p>To implement the sorting you need to think about what you want to achieve.&#160; What is it that we want to sort?&#160; The states.&#160; And these are shown as categories on the chart, so we should take a look at its properties.&#160; As shown in the following screenshot, right-clicking on the [StateProvinceName] button gives a pop-up menu.&#160; Select Category Group Properties.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image81.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Context menu for Category Group" border="0" alt="Context menu for Category Group" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb7.png" width="475" height="99" /></a></p>
<p>Then we need to think about how we want the states to get sorted.&#160; For that we should look at what is being shown as data of the chart.&#160; In our case that is the sum of the AnnualSales field.</p>
<p>In the Category Group Properties, select the page called Sorting.&#160; Clicking the Add button will add a line in the sorting options list.&#160; Use the following expression for the “Sort by” field:</p>
<pre class="code">=Sum(Fields!AnnualSales.Value)</pre>
<p>As we want to sort the largest values first, select “Z to A” for the Order dropdown.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image82.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Category Group Properties" border="0" alt="Category Group Properties" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb8.png" width="476" height="394" /></a></p>
<p>Right, time to have another look at our report in Preview.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image83.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Sorted Pie Chart" border="0" alt="Sorted Pie Chart" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb9.png" width="557" height="367" /></a></p>
<p>So, we went from a colorful mess to an ordered colorful mess.&#160; Chaos has been reduced a bit, but this is still one difficult-to-read report.</p>
<p>On to the next improvement!</p>
<h2>Limiting The Pies</h2>
<p>As you have noticed, a pie chart is not suitable to show that many categories.&#160; We need to find a way to reduce the slices.&#160; One way to do that is by adding a filter.&#160; Another way is to add the smallest slices together into one slice.&#160; This can be interesting in cases where we want to use all the data but we’re only interested in the larger slices.&#160; Luckily, this can be done using standard pie chart properties.</p>
<p>Click on the pie itself, this will select the Chart Series.&#160; One way to tell if you’ve selected the correct part of the chart is by looking at the Properties pane.&#160; Its selection should show something like “<strong>AnnualSales</strong> Chart Series”, where <strong>AnnualSales</strong> is the name of the chart series.&#160; Another way to tell is by the small white selector bulbs: they should be surrounding the pie.</p>
<p>Now, among the properties of the Chart Series you will find a property group called CustomAttributes.&#160; Open this one by clicking the plus icon in front of it.&#160; Change the <strong>CollectedStyle</strong> property to SingleSlice.&#160; This tells the chart that we want to group the smallest slices into one slice.</p>
<p>Other interesting properties here are <strong>CollectedThreshold </strong>and <strong>CollectedThresholdUsePercent</strong>.&#160; I’ve put CollectedThreshold to 2 and CollectedThresholdUsePercent to True (which is its default).&#160; This means that any slice smaller than 2 percent of the pie will be added into the “collected slice”.</p>
<p>More useful properties are <strong>CollectedLabel</strong>, that’s the text that is shown on the slice itself, and <strong>CollectedLegendText</strong>, the text shown in the legend.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Chart Series - collected slice properties" border="0" alt="Chart Series - collected slice properties" src="http://blog.hoegaerden.be/wp-content/uploads/image84.png" width="382" height="248" /></p>
<p>The CollectedStyle property has another option besides the one I’ve shown, called CollectedPie.&#160; Choosing that will generate a second pie next to the main one to represent all the small slices.&#160; See the following screenshot for what it looks like.&#160; In some cases this may be an interesting option but not in our example here.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image85.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Pie Chart showing a CollectedPie" border="0" alt="Pie Chart showing a CollectedPie" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb10.png" width="599" height="339" /></a></p>
<p>The collected pie can also show labels by setting the <strong>CollectedChartShowLabels </strong>property to True, and the categories shown on the collected pie can be shown in the pie’s legend by setting <strong>CollectedChartShowLegend </strong>to True.</p>
<p>If you’d like the collected slice to jump out, there’s a property called <strong>CollectedSliceExploded</strong>.&#160; Setting it to True will produce something like the following:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Exploded Collected Slice" border="0" alt="Exploded Collected Slice" src="http://blog.hoegaerden.be/wp-content/uploads/image86.png" width="424" height="387" /></p>
<p>As you have noticed, the previous screenshots have started to show text on the slices.&#160; This can be easily activated by right-clicking the pie and selecting the Show Data Labels menu item.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Context menu on pie chart - Show Data Labels" border="0" alt="Context menu on pie chart - Show Data Labels" src="http://blog.hoegaerden.be/wp-content/uploads/image87.png" width="196" height="154" /></p>
<p>And the next screenshot shows what our chart currently looks like.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image88.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Pie chart with collected slice" border="0" alt="Pie chart with collected slice" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb11.png" width="552" height="395" /></a></p>
<p>The small slices have been replaced by a really large one, and the text on the large slice is our customized version.&#160; The other slices are showing some rather large numbers, so we still have some work to do.</p>
<h2>Displaying Percentages</h2>
<p>Let’s customize the label shown on the slices.&#160; As the numbers are really large, I recommend to divide them by 1,000.&#160; As long as it’s clearly mentioned on the report, it will make everything more readable.</p>
<p>Furthermore I’ll show you how to use built-in chart keywords (only available to ToolTips, custom legend text, and data point label properties), such as #PERCENT.</p>
<p>Right-click on one of the data labels and select Series Label Properties.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Context menu of data labels - Series Label Properties" border="0" alt="Context menu of data labels - Series Label Properties" src="http://blog.hoegaerden.be/wp-content/uploads/image89.png" width="255" height="156" /></p>
<p>Click the expression (fx) button on the General page and enter the following expression:</p>
<pre class="code">=FormatCurrency(Sum(Fields!AnnualSales.Value) / 1000, 0) &amp; <span style="color: #a31515">&quot; (#PERCENT{P1})&quot;</span></pre>
<p>The first part divides the sum of AnnualSales by 1,000 and then applies the FormatCurrency function to the result.&#160; The second parameter for FormatCurrency tells the function that we don’t want any decimals.&#160; The result of this function call is concatenated with the second part using Visual Basic string concatenation (&amp;).</p>
<p>The second part looks like a regular string but it contains a built-in keyword: #PERCENT.&#160; This will show the percentage that the slice represents.&#160; Furthermore, there’s a custom string formatter appended: P1.&#160; By default the percentage would show 2 decimals.&#160; This way it will only use one digit for the decimal fraction.</p>
<p>See <a title="SQL Server 2008 BOL - Formatting Data Points on a Chart" href="http://msdn.microsoft.com/en-us/library/bb677551.aspx" target="_blank">here</a> for a list of all built-in keywords and <a title=".NET Formatting Types" href="http://msdn.microsoft.com/en-us/library/fbxft59x.aspx" target="_blank">this page</a> for more information on the available formatting options.</p>
<p>And following screenshot shows what our chart now looks like.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image90.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Pie chart showing percentages on slices" border="0" alt="Pie chart showing percentages on slices" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb12.png" width="579" height="413" /></a></p>
<p>I’ve also given it a clear title, decreased the Data Label font size to 8 and moved the legend down.</p>
<p>To move the legend: right-click it, select Legend Properties and play with the radio buttons for the Legend Position.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image91.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Legend Properties" border="0" alt="Legend Properties" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb13.png" width="463" height="425" /></a></p>
<p>So, we’ve now got a fairly readable chart.&#160; It’s not perfect, some labels are overlapping, but it’s doable.&#160; However, we won’t rest here.&#160; On to the next tip.</p>
<h2>Rotating The Pie</h2>
<p>Some people may ask you, “Why on earth does the first slice (the blue one representing 10.6% in our example) start at this weird angle at 4 o’clock?&#160; Why can’t it start at 12:00?”.</p>
<p>Again we’re lucky because this can be controlled using a standard property.&#160; Among the Chart Series CustomAttributes property group there are still some properties which haven’t been mentioned earlier.&#160; One of them is called <strong>PieStartAngle</strong>.&#160; By default it is set to zero.&#160; Funny enough, zero stands for 30°.&#160; Try it out and enter 30 for the property value.&#160; Did you see the effect?&#160; Indeed, nothing happens!&#160; Now enter 90.&#160; Did you see the chart rotate, even in Design mode?&#160; Switch to Preview to get a better view of what the impact is.&#160; As you can see, setting it to 90 will cause the first slice to start at 06:00.&#160; To make it start at 12:00, we thus need to set the property to 270 degrees.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image92.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Pie Chart with customized rotation angle" border="0" alt="Pie Chart with customized rotation angle" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb14.png" width="599" height="427" /></a></p>
<h2>Labels Outside Pie Chart</h2>
<p>Other people may tell you, “But I don’t want all these labels on the pie itself, I want them next to it.”.</p>
<p>We’re still lucky because again this can be achieved using standard properties.&#160; Still in the Chart Series CustomAttributes, there’s a property named <strong>PieLabelStyle</strong>.&#160; Its default value is Inside.&#160; Switching it to Outside will render the labels outside the pie, with lines attaching them to their respective slice.</p>
<p>Other interesting properties for the outside labeling are <strong>3DLabelLineSize </strong>and <strong>MinimumRelativePieSize</strong>.</p>
<p><strong>3DLabelLineSize</strong> defines the amount of space used for drawing the line between the label and its corresponding slice and is a percentage of its default size.&#160; Values range from 30 to 200.&#160; I’ve put it to 30 to get as much space as possible for the pie itself and the labels.</p>
<p><strong>MinimumRelativePieSize </strong>represents a percentage of the chart area size and defines the minimum acceptable pie size.&#160; Values range from 10 to 70.&#160; I’ve put this one to 70 to maximize the size of the pie.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Chart Series properties with properties for outside labeling highlighted" border="0" alt="Chart Series properties with properties for outside labeling highlighted" src="http://blog.hoegaerden.be/wp-content/uploads/image93.png" width="383" height="380" /></p>
<p>With these modifications we’ve actually gotten some extra space for the labels.&#160; Let’s take advantage of that and add extra information in the labels.&#160; Change the Data Label expression to the following:</p>
<pre class="code">=<span style="color: #a31515">&quot;#LEGENDTEXT&quot; </span>&amp; vbcrlf &amp;
FormatCurrency(Sum(Fields!AnnualSales.Value) / 1000, 0) &amp; <span style="color: #a31515">&quot; (#PERCENT{P1})&quot;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<div class="code"><span style="color: #808080"></span></div>
<p>Our expression uses another built-in keyword: #LEGENDTEXT.&#160; This will add the legend text to the label itself, which means the legend becomes obsolete.&#160; So I’ve removed it.</p>
<p>And this is what our chart now looks like:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image94.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Pie chart showing labels on the outside" border="0" alt="Pie chart showing labels on the outside" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb15.png" width="548" height="384" /></a></p>
<p>With Halloween coming up I thought it would be nice to create a spidery chart <img src='http://blog.hoegaerden.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h2>One More Custom Attribute</h2>
<p>I’ve already mentioned several CustomAttribute properties of the Chart Series and I’d like to mention one more.&#160; This property is called <strong>PieDrawingStyle </strong>and it will only appear in the list of properties when 3D is not enabled.&#160; After disabling 3D I could set it to either SoftEdge or Concave.&#160; I also noticed that labels outside of a pie chart will only have lines attached to them when rendered in 3D, so I’ve switched back to Inside for the PieLabelStyle property.</p>
<p>This is what SoftEdge looks like.&#160; I think it’s rather nice.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image95.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Pie chart using SoftEdge drawing style" border="0" alt="Pie chart using SoftEdge drawing style" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb16.png" width="477" height="518" /></a></p>
<h2>Custom Coloring</h2>
<p>To conclude, there may be some people who tell you, “I don’t like those colours, and I don’t like any of the predefined sets.&#160; I want to specify custom colours.”.</p>
<p>So again we’re lucky because even that is supported by default.</p>
<p>To get started with our color customization, select the chart object.&#160; To know if you’ve made the correct selection, the Property pane should show “Chart” as non-bold part of the dropdown.&#160; Alternatively you can just use that dropdown to select the Chart.&#160; As Chart is a main object on the report, it is shown in the list (whereas parts of a Chart, such as Chart Series and Chart Area, are not shown in that list).</p>
<p>With the Chart selected, locate the <strong>Palette </strong>property.&#160; By default it is set to BrightPastel.&#160; In case you’re happy with one of the predefined palettes you can just select it here.&#160; But we go for Custom, located at the bottom.</p>
<p>Next, locate the <strong>CustomPaletteColors </strong>property.&#160; Selecting the property will show a button with an ellipsis as button text.&#160; Click this button to get to the ReportColorExpression Collection Editor (what a name for a popup window!).&#160; This window allows you to specify a list of colors.&#160; I’ve specified the following 10 colors:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ReportColorExpression Collection Editor" border="0" alt="ReportColorExpression Collection Editor" src="http://blog.hoegaerden.be/wp-content/uploads/image96.png" width="499" height="368" /></p>
<p>And finally this is what our report looks like.&#160; To stay in the theme, I’ve specified some colors which are suitable for Halloween-time charting.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image97.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Pie chart with custom colors - Halloween-style!" border="0" alt="Pie chart with custom colors - Halloween-style!" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb17.png" width="616" height="437" /></a></p>
<h3>Coloring Consistency Using Dynamic Colors</h3>
<p>And now to really conclude this article I’d like to mention one additional tip related to chart coloring.&#160; In some occasions it may be interesting to have coloring consistency between different charting periods.&#160; With that I mean that California would always show in grey, no matter whether it came first or not, Washington as brown, and so on.&#160; This is currently not the case.&#160; With the current implementation it’s the first pie that gets the grey color, the second pie is brown, and so on.</p>
<p>The best way to achieve that is to store the colors in the database and then fetch them in the same dataset that is used to retrieve the chart data.&#160; The AdventureWorks database hasn’t got any color codes stored so I’ll just illustrate what I mean using a little cheat.</p>
<p>In order to get our dynamic coloring working, we will override the colors from the palette.&#160; This is how it’s done.&#160; Right-click on the pie and select Series Properties.&#160; Select the Fill page and click the Expression (fx) button to define the color.&#160; In the case where you’re selecting the color code as one of the database fields, your expression would look similar to this (assuming that colors are stored using their 6-digit hexadecimal representation with 000000 being black and FFFFFF being white):</p>
<pre class="code">=<span style="color: #a31515">&quot;#&quot; </span>&amp; Fields!ColourCode.Value</pre>
<p>To imitate dynamic coloring I’ve used the following expression:</p>
<pre class="code">=Switch
(
    Fields!StateProvinceName.Value = <span style="color: #a31515">&quot;California&quot;</span>, <span style="color: #a31515">&quot;Blue&quot;</span>,
    Fields!StateProvinceName.Value = <span style="color: #a31515">&quot;Washington&quot;</span>, <span style="color: #a31515">&quot;Red&quot;</span>,
    Fields!StateProvinceName.Value = <span style="color: #a31515">&quot;Florida&quot;</span>, <span style="color: #a31515">&quot;Green&quot;</span>,
    <span style="color: blue">True </span>, <span style="color: #a31515">&quot;#888888&quot;
</span>)</pre>
<p>The expression gives three states their own color and all the others will be colored a kind of grey.</p>
<p>This is what it looks like:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image98.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Pie Chart using dynamic colors" border="0" alt="Pie Chart using dynamic colors" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb18.png" width="569" height="401" /></a></p>
<p>So, I hope you’ve enjoyed reading this article.&#160; Feel free to post any comments should you wish to do so, and&#8230; happy charting!</p>
<h2>References</h2>
<p><a title="SQL Server 2008 Books Online: Pie Charts" href="http://msdn.microsoft.com/en-us/library/cc281303.aspx" target="_blank">SQL Server 2008 Books Online: Pie Charts</a></p>
<p><a title="How to: Collect Small Slices on a Pie Chart" href="http://msdn.microsoft.com/en-us/library/cc281305.aspx" target="_blank">How to: Collect Small Slices on a Pie Chart</a></p>
<p><a title="Formatting Data Points on a Chart" href="http://msdn.microsoft.com/en-us/library/bb677551.aspx" target="_blank">Formatting Data Points on a Chart</a></p>
<p><a title="How to: Define Colors on a Chart Using a Palette" href="http://msdn.microsoft.com/en-us/library/cc281182.aspx" target="_blank">How to: Define Colors on a Chart Using a Palette</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2009/10/25/pie-chart-techniques/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Chart Optimization Tips</title>
		<link>http://blog.hoegaerden.be/2009/07/20/chart-optimization-tips/</link>
		<comments>http://blog.hoegaerden.be/2009/07/20/chart-optimization-tips/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 13:40:37 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[Charting]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Reporting Services 2008]]></category>
		<category><![CDATA[SSRS]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2009/07/20/chart-optimization-tips/</guid>
		<description><![CDATA[Here are some optimization techniques that can be used when creating charts in SQL Server 2008 Reporting Services.  These tips will probably be already known to experienced chart developers, but freshmen charters may spent some time searching how to achieve something before actually finding it, if finding it at all.  I know because I’ve been [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some optimization techniques that can be used when creating charts in SQL Server 2008 Reporting Services.  These tips will probably be already known to experienced chart developers, but freshmen charters may spent some time searching how to achieve something before actually finding it, if finding it at all.  I know because I’ve been there myself when I started out and I also know because I’ve seen questions on forums related to this.</p>
<p>Okay, enough vague intro-words, let’s get concrete now.  In the following example I’ll be creating a regular column chart.</p>
<h2>X-axis: show all labels</h2>
<p>By default, a chart in SSRS will automatically position the labels on the X-axis as it best fits.  However, one of these options includes hiding labels when the chart feels there are too many to show.  As you can guess, this is not always what we want.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image33.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Column bar chart without any changes to its default settings" src="http://blog.hoegaerden.be/wp-content/uploads/image-thumb18.png" border="0" alt="Column bar chart without any changes to its default settings" width="496" height="283" /></a></p>
<p>Have a look at the chart above and try to guess what you’re seeing.  Difficult, huh?  Let’s make some changes to it.</p>
<p>First we start with some basics like giving it a clear title.  This chart shows the annual revenue per state/province, split up by store specialty.  The states or provinces shown are those of the selected country.  I would call it “Annual Revenue per State/Province by Specialty for &lt;SELECTED_COUNTRY&gt;”.  As you probably know, the chart’s title can be edited by giving it a single-click.  However, this does not give you the option to build an expression so unless you want to type it all from memory, here’s another option.  You can right-click on the chart’s title.  This gives you a pop-up menu with Title Properties… as one of the options.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Right-click menu on chart title" src="http://blog.hoegaerden.be/wp-content/uploads/image34.png" border="0" alt="Right-click menu on chart title" width="244" height="106" /></p>
<p>Selecting that one will give you the Chart Title Properties where you have the familiar Expression Builder icon next to Title Text textbox.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Chart Title Properties" src="http://blog.hoegaerden.be/wp-content/uploads/image35.png" border="0" alt="Chart Title Properties" width="493" height="410" /></p>
<p>This is my expression:</p>
<div class="code"><span style="color: #0000ff;">=</span><span style="color: #808080;">&#8220;Annual Revenue per State/Province by Specialty for &#8221; </span><span style="color: #000000;">&amp;</span><span style="color: #808080;"> </span><span style="color: #000000;">Parameters!Country.Value</span></div>
<p>Also, let’s move the legend to the upper middle to make extra horizontal space for all those bars.  This can be done through the Legend Properties.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Legend Properties" src="http://blog.hoegaerden.be/wp-content/uploads/image36.png" border="0" alt="Legend Properties" width="499" height="457" /></p>
<p>Lastly, now that we’ve freed up some space for the chart area, we’ll modify the X-axis properties so that it shows all labels.</p>
<p>When opening up the axis properties for the X-axis on a column chart you get the Category Axis Properties screen.  Like all other property screens, this is also one with several pages.  You see that one of the pages is called Labels and as you want it to show all labels, that’s were you start looking.  Well, stop looking, that’s the wrong place.  The option that you need is located in the first page, the Axis Options, and its called Interval.  This is the interval between each label on the axis, and by default it is set to Auto.  As we want all labels, change it to 1.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image37.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Category Axis Properties" src="http://blog.hoegaerden.be/wp-content/uploads/image-thumb19.png" border="0" alt="Category Axis Properties" width="499" height="457" /></a></p>
<p>Following screenshot shows what the result looks like:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image38.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Column chart showing all labels on category axis" src="http://blog.hoegaerden.be/wp-content/uploads/image-thumb20.png" border="0" alt="Column chart showing all labels on category axis" width="496" height="281" /></a></p>
<p>Better, but we’re not quite there yet.</p>
<h2>X-axis: rotate labels in all directions</h2>
<p>Right now the labels on the X-axis are difficult to read unless we turn our screen 90 degrees clockwise.  Let’s dive again into the Category Axis Properties to put them diagonally.  On the Labels page there’s an option to specify the Label Rotation Angle.   To be able to do this you need to activate the Disable auto-fit radio button.  Putting 45 as value will give the following:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Labels rotated 45 degrees" src="http://blog.hoegaerden.be/wp-content/uploads/image39.png" border="0" alt="Labels rotated 45 degrees" width="211" height="150" /></p>
<p>The labels are rotated 45 degrees.  But not in the direction that I would prefer.  It’s nicer when they’re positioned from bottom-left to top-right.  So you start increasing the rotation value.  However, once you’re past 90 you notice that the labels stay vertically, so 135 degrees does not put them in the direction as you’d hoped.  The answer is quite simple, once you know it.  As we want the opposite of our 45 degrees, and it’s not 135, try –45 <img src='http://blog.hoegaerden.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image40.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Category Axis Properties with Label rotation angle set to a negative value" src="http://blog.hoegaerden.be/wp-content/uploads/image-thumb21.png" border="0" alt="Category Axis Properties with Label rotation angle set to a negative value" width="494" height="453" /></a></p>
<p>Indeed, that gives the following result (I’ve also removed the X-axis title).</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image41.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Column chart with optimized X-axis" src="http://blog.hoegaerden.be/wp-content/uploads/image-thumb22.png" border="0" alt="Column chart with optimized X-axis" width="491" height="262" /></a></p>
<p>To finalize the X-axis optimization, I’ve added sorting so that the States/Provinces are sorted alphabetically.  This is a recommended design practice to keep your different charts consistent.</p>
<p>To get the labels sorted, you should not look into the Axis properties but in the Category Group Properties:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Pop-up menu to get to the Category Group Properties" src="http://blog.hoegaerden.be/wp-content/uploads/image42.png" border="0" alt="Pop-up menu to get to the Category Group Properties" width="489" height="252" /></p>
<p>On the Sorting page just add the field that’s shown on the X-axis.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image43.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Category Group Properties with sorting" src="http://blog.hoegaerden.be/wp-content/uploads/image-thumb23.png" border="0" alt="Category Group Properties with sorting" width="495" height="410" /></a></p>
<h2>Y-axis: make numbers readable</h2>
<p>So, now that we’re done with the X-axis, let’s move on to the next letter of the alphabet.  Our Y-axis (also known as Value Axis on a column chart) is not very readable at the moment.  The numbers are too large and there’s no formatting.  You don’t even see that this is a currency value.</p>
<p>This time we need the Number page of the Value Axis Properties.  We want:</p>
<ul>
<li>no decimals</li>
<li>a thousands separator</li>
<li>the numbers divided by 1000 (that’s the “Show values in” setting)</li>
<li>a dollar sign in front of the value</li>
</ul>
<p>To get all this, you can set the options as shown in the screenshot:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image44.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Value Axis Properties optimized for large currencies" src="http://blog.hoegaerden.be/wp-content/uploads/image-thumb24.png" border="0" alt="Value Axis Properties optimized for large currencies" width="485" height="444" /></a></p>
<p>And here’s our chart again:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image45.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Chart with optimized Y-axis" src="http://blog.hoegaerden.be/wp-content/uploads/image-thumb25.png" border="0" alt="Chart with optimized Y-axis" width="474" height="219" /></a></p>
<p>Additionally, the axis title has also gotten a clear value.  It indicates how the values should be read.</p>
<h2>Y-axis: move to right-hand side</h2>
<p>To conclude this article I’ll show you how to move the Y-axis to the other side of the chart.  This may seem like an odd thing to do, but sometimes the business people want to display a chart that way so you’d better have strong convincing skills or know how to do it.  Or both <img src='http://blog.hoegaerden.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>In fact, a chart has got two Value axes and two Category axes, a Primary and a Secondary.  The Primary axes are the ones used right now.  To move the visible axis to the other side, it’s not through the Value Axis Properties as you might think (I think you’re getting the hang of it now, right? <img src='http://blog.hoegaerden.be/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .  No, all you need to do is move all data series to the secondary axis.  This can be done through the Series Properties.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image46.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Pop-up menu on data series" src="http://blog.hoegaerden.be/wp-content/uploads/image-thumb26.png" border="0" alt="Pop-up menu on data series" width="475" height="182" /></a></p>
<p>The Axis and Chart Area page is the one you’re after.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image47.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Series Properties with Secondary Value axis activated" src="http://blog.hoegaerden.be/wp-content/uploads/image-thumb27.png" border="0" alt="Series Properties with Secondary Value axis activated" width="483" height="435" /></a></p>
<p>That will give us the following end result:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image48.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Column chart with Y-axis on the right-hand side" src="http://blog.hoegaerden.be/wp-content/uploads/image-thumb28.png" border="0" alt="Column chart with Y-axis on the right-hand side" width="470" height="233" /></a></p>
<p>BTW: you will need to re-do the axis formatting when you switch to the secondary axis so better start with axis activation before formatting it.</p>
<p>Happy charting!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2009/07/20/chart-optimization-tips/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
