Hi,
I have a problem and would appreciate your help.
I would like to show on a HTML Pie Chart two values: the actual value (units) and a percentage (%).
So for example in such format: 35% (120units) or 20% (110units) and so on. This should appear as a PieLabel and additionally as Tooltip (when someone moves cursor over pie).
For each data I have counted both values.
I prefer the programmatic creation of chart :) (in .aspx only the minimum)
So my code looks like:
chart.aspx:
chart.aspx.cs:
I have a problem and would appreciate your help.
I would like to show on a HTML Pie Chart two values: the actual value (units) and a percentage (%).
So for example in such format: 35% (120units) or 20% (110units) and so on. This should appear as a PieLabel and additionally as Tooltip (when someone moves cursor over pie).
For each data I have counted both values.
I prefer the programmatic creation of chart :) (in .aspx only the minimum)
So my code looks like:
chart.aspx:
<
telerik:RadHtmlChart
runat
=
"server"
ID
=
"RadHtmlChart1"
Width
=
"500"
Height
=
"500"
Transitions
=
"true"
>
<
Appearance
>
<
FillStyle
BackgroundColor
=
"White"
/>
</
Appearance
>
<
Legend
>
<
Appearance
BackgroundColor
=
"White"
Position
=
"Right"
Visible
=
"true"
/>
</
Legend
>
<
PlotArea
>
<
Appearance
>
<
FillStyle
BackgroundColor
=
"White"
/>
</
Appearance
>
<
Series
>
</
Series
>
</
PlotArea
>
</
telerik:RadHtmlChart
>
chart.aspx.cs:
private
void
ShowChart()
{
PieSeries pieSeries =
new
PieSeries();
listContactsAmount = report.GetCampaignData(iCampaignId);
// get my data
if
(listContactsAmount !=
null
&& listContactsAmount.Count > 0)
{
int
sum = 0;
foreach
(DataRow row
in
listContactsAmount.Rows)
{
sum = sum + (
int
)row[
"ContactsAmount"
];
}
pieSeries.StartAngle = 90;
pieSeries.LabelsAppearance.DataFormatString =
"{0}"
;
pieSeries.LabelsAppearance.Position = Telerik.Web.UI.HtmlChart.PieLabelsPosition.Circle;
pieSeries.TooltipsAppearance.DataFormatString =
"{0}"
;
SeriesItem seriesItem =
null
;
foreach
(DataRow row
in
listContactsAmount.Rows)
{
seriesItem =
new
SeriesItem();
string
contactsStatus = (
string
)row[
"ContactsStatus"
];
int
contactsAmount = (
int
)row[
"ContactsAmount"
];
// the first value to display
decimal
percentage = Math.Round(Decimal.Divide((
decimal
)contactsAmount, (
decimal
)sum), 4);
// the second value to display - WHERE PUT IT ?
seriesItem.Name = contactsStatus;
seriesItem.YValue = contactsAmount;
if
(contactsStatus.Equals(
"Ok"
))
{
seriesItem.BackgroundColor = Color.GreenYellow;
seriesItem.Exploded =
true
;
}
else
{
seriesItem.BackgroundColor = Color.Red;
seriesItem.Exploded =
true
;
}
pieSeries.Items.Add(seriesItem);
}
RadHtmlChart1.PlotArea.Series.Add(pieSeries);
}
}