我想用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>谢谢
发布于 2019-07-25 14:31:56
如果您希望图例格式与标签不同,则必须更改其格式。你用LegendText来做。例:
ChartAb.Series[0].LegendText = "#AXISLABEL";如Microsoft文档https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.datavisualization.charting.legend所写
如果您有饼图并设置了Label属性,它还将将图例文本设置为为标签设置的值。如果要将文本设置为不同的值,则可以设置LegendText属性。在大多数情况下,您可能希望将LegendText属性设置为"#AXISLABEL“或"#VALX”。
https://stackoverflow.com/questions/55121340
复制相似问题