Click here to Skip to main content
15,919,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to replace MSCHART from my projects with Chart helpers (System.Web.Helpers) but I'm having a lot of difficulties:

1) How can I insert percentage values into a PIE chart?
2) Can I move the chart Value outside pie?

What I have tried:

Chart myChart = new Chart(width: 800, height: 400, themePath: "~/xml/hst_pie_tech.xml",  theme: ChartTheme.Vanilla3D)
           .AddTitle("Volume ")
                   chartType: "Pie",
                   xValue: dataView, xField: "Technology",
                   yValues: dataView, yFields: "Qty",
                   markerStep: 1

<?xml version="1.0" encoding="utf-8" ?>

		<ChartArea Name="Default" _Template_="All">
				LineColor="0, 0, 0"
				TitleFont="{0}, 14pt, style=Bold"
				TitleForeColor="0, 0, 0"
				<LabelStyle Font="{0}, 6.75pt, GdiCharSet=0" ForeColor="0, 0, 0" />
				TitleFont="{0}, 18pt, GdiCharSet=0"	>
				<LabelStyle Font="{0}, 6.75pt, GdiCharSet=0" ForeColor="0, 0, 0" />

		<Title _Template_="All" Font="{0}, 14pt, style=Bold" ForeColor="0, 0, 0"></Title>
			Color="153, 204, 255" 
			BorderColor="164, 164, 164" 
			ShadowColor="128, 128, 128, 128" 
			Font="{0}, 8pt" 
			BackSecondaryColor="0, 102, 153" 
			LabelForeColor="0, 0, 0"
			<SmartLabelStyle Enabled="True" />
		<Legend Alignment="Center" Docking="Left" Name="Technology" Font="{0}, 10pt, style=Italic, GdiCharSet=0">

	<BorderSkin PageColor="Control" BackColor="CornflowerBlue" BackSecondaryColor="CornflowerBlue" />
Updated 5-Mar-24 0:32am
Richard Deeming 5-Mar-24 4:33am    
Does this SO answer[^] help? It's for a doughnut chart, but based on the property name, it looks like that uses the same properties as the pie chart.
<Series Name="Default" CustomProperties="PieLabelStyle = Outside" Label="Very very long label (#VAL)"></Series>

If you want to use percentages as the numbers, just assign the values to the series. They are just numbers after all. If what you are asking is how do you show the %age as a label, simply use this markup against your ChartArea.
<AxisY >
  <LabelStyle Format="{0:p}" />
Share this answer
I tried to apply a mix of the two solutions
It seems to work. Thanks for the quick support

    CustomProperties="PieLabelStyle = Outside"
    Label="Qty:#VAL / (#PERCENT)"
    <SmartLabelStyle Enabled="True" />
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900