Reputation: 29
i wanted to format the values inside a pie chart i am using asp.net chart control.
values are coming from database, and are showing like this "12345678", but i want to show them like this "12,345,678".
i already tried this
ChartAb.Series[0].Label = "#VALY{#,###}";
it converts the values to "12,345,678" but it also changes the Chart legend, where labels are replaced with values like Purchased is replaced with "12,345,234" and remaining is replaced with "32,123"
so its not useful for me . how can i achieve comma format without changing labels.
i also tried to format value in sql query, it shows results as i wanted in sql server but not showing that format in chart.
here is my cs page code
protected void Budget_Issuance_HandsetChart_Pie()
{
// Convert.ToDecimal(number).ToString("#,##0.00");
Budget_Issuance_Handset_Chart_Pie.Visible = true;
string query = string.Format("select b.issuanceType, Format(SUM(b.budgetAmount), '##,##0') as Budget from tblbudget b inner join tblContract c on b.contractID=c.contractID where b.budgetType='Handset' " + queryVal+" group by b.issuanceType");
DataTable dt = GetData(query);
Budget_Issuance_Handset_Chart_Pie.DataSource = dt;
foreach (Series series in Budget_Issuance_Handset_Chart_Pie.Series)
{
series.ChartType = SeriesChartType.Pie;
}
// Chart1.Series[0].ChartType = (SeriesChartType)int.Parse("10");
Budget_Issuance_Handset_Chart_Pie.Legends[0].Enabled = true;
Budget_Issuance_Handset_Chart_Pie.Series[0].XValueMember = "issuanceType";
Budget_Issuance_Handset_Chart_Pie.Series[0].YValueMembers = "Budget";
Budget_Issuance_Handset_Chart_Pie.Series[0].IsValueShownAsLabel = true;
Budget_Issuance_Handset_Chart_Pie.Series[0].Label = "#VALY{#,###}";
Budget_Issuance_Handset_Chart_Pie.DataBind();
// UtilisedBudget(null,EventArgs.Empty);
}
and here is aspx page code
<asp:Chart ID="Budget_Issuance_Handset_Chart_Pie" runat="server" Height="400px" Width="500px" Visible="false">
<Titles>
<asp:Title ShadowOffset="3" Name="Items" />
</Titles>
<Legends>
<asp:Legend Alignment="Center" Docking="Bottom" IsTextAutoFit="False" Name="Default"
LegendStyle="Row" />
</Legends>
<Series>
<asp:Series Name="Default" />
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartAreaHandsetIssuance" BorderWidth="0" />
</ChartAreas>
</asp:Chart>
Thanks
Upvotes: 0
Views: 1729
Reputation: 1525
You have to change the Legend format also if you want it to be different than the Label. You do it with LegendText
.
Exemple:
ChartAb.Series[0].LegendText = "#AXISLABEL";
As written in Microsoft documentation https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.datavisualization.charting.legend
If you have a pie chart and you set the Label property, it will also set the legend text to the value you set for the labels. If you want to set the text to a different value, you can set the LegendText property. In most cases, you would want to set the LegendText property to "#AXISLABEL" or "#VALX".
Upvotes: 1