我想使用asp.net图表控件格式化饼图中的值。
值来自数据库,并显示为“ 12345678”,但我想显示为“ 12,345,678”。
我已经尝试过
ChartAb.Series[0].Label = "#VALY{#,###}";
它将值转换为“ 12,345,678”,但它还会更改“图表图例”,其中的标签将替换为诸如 购买的被替换为“ 12,345,234” 其余的则替换为“ 32,123”
所以它对我没有用。如何在不更改标签的情况下实现逗号格式。
我还尝试在sql查询中设置值的格式,它在sql server中显示了我想要的结果,但未在图表中显示该格式。
这是我的CS页面代码
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);
}
这是aspx页面代码
<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>
谢谢
答案 0 :(得分:0)
如果您希望图例格式与标签不同,则还必须更改图例格式。您可以使用LegendText
进行操作。
例子:
ChartAb.Series[0].LegendText = "#AXISLABEL";
如Microsoft文档https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.datavisualization.charting.legend
中所述如果您有一个饼图并设置了Label属性,它也会 将图例文本设置为您为标签设置的值。如果你想 要将文本设置为其他值,可以设置LegendText 属性。在大多数情况下,您需要设置LegendText属性 到“ #AXISLABEL”或“ #VALX”。