gpt4 book ai didi

c# - 图表系列标签为百分比

转载 作者:行者123 更新时间:2023-11-30 21:56:28 29 4
gpt4 key购买 nike

我通过 System.Web.UI.DataVisualization.Charting 在 MS Visual Studio 2010 中使用图表组件。我在使用柱形图时遇到问题,我想在其中将标签显示为百分比。该图显示了全年每个月的决策数量(正面 - 绿色,负面 - 红色,中性 - 蓝色)。麻烦的是,如果我使用以下命令...

ChartDecisionDyn.Series["Positive"].IsValueShownAsLabel = true;
ChartDecisionDyn.Series["Positive"].Label = "#PERCENT";

...我没有得到预期的百分比结果。显示的结果表示某个月的积极决定数/全年的积极决定数,但我想要的结果是某个月的积极决定数/某个月的总决定数。有人有什么建议吗?在此先感谢您的帮助。

可以看我的图的详情here

最佳答案

看不到图表的图像,但我这样做了:

<asp:Chart ID="Chart1" runat="server" DataSourceID="ObjectDataSource1" Width="451px">
<Series>
<asp:Series Name="Series1" XValueMember="Month" YValueMembers="Percentage"></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<AxisY>
<LabelStyle Format="P0" />
</AxisY>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>

或者这个:

    Chart1.ChartAreas[0].AxisY.LabelStyle.Format = "P0";

得到这个:

enter image description here

编辑:这个怎么样:

<asp:Chart ID="Chart1" runat="server" DataSourceID="ObjectDataSource1" Width="451px">
<Series>
<asp:Series Name="Series1" XValueMember="Month" YValueMembers="Percentage" IsValueShownAsLabel="True" LabelFormat="F2"></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<AxisY>
<MajorGrid LineColor="DarkGray" LineDashStyle="Dot" />
<LabelStyle Format="P0" />
</AxisY>
<AxisX>
<MajorGrid Enabled="False" />
</AxisX>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="WebApplication9.DataPoint" DeleteMethod="Remove" InsertMethod="Add" SelectMethod="ToArray" TypeName="WebApplication9.DataPointList" UpdateMethod="Add"></asp:ObjectDataSource>

enter image description here

编辑 2:添加多个系列。

<asp:Chart ID="Chart1" runat="server" DataSourceID="ObjectDataSource1" Width="499px">
<Series>
<asp:Series Name="Percent" XValueMember="Month" YValueMembers="Percent" IsValueShownAsLabel="True" LabelFormat="P0" Legend="Legend1" YAxisType="Secondary"></asp:Series>
<asp:Series ChartArea="ChartArea1" IsValueShownAsLabel="True" LabelFormat="N0" Legend="Legend1" Name="Positive" XValueMember="Month" YValueMembers="Positive">
</asp:Series>
<asp:Series ChartArea="ChartArea1" IsValueShownAsLabel="True" LabelFormat="N0" Legend="Legend1" Name="Neutral" XValueMember="Month" YValueMembers="Neutral">
</asp:Series>
<asp:Series ChartArea="ChartArea1" IsValueShownAsLabel="True" LabelFormat="F0" Legend="Legend1" Name="Negative" XValueMember="Month" YValueMembers="Negative">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<AxisY>
<MajorGrid LineColor="DarkGray" LineDashStyle="Dot" />
</AxisY>
<AxisX>
<MajorGrid Enabled="False" />
</AxisX>
<AxisY2>
<MajorGrid LineColor="DarkGray" LineDashStyle="Dot" />
<LabelStyle Format="P0" />
</AxisY2>
</asp:ChartArea>
</ChartAreas>
<Legends>
<asp:Legend Alignment="Center" Docking="Top" Name="Legend1">
</asp:Legend>
</Legends>
</asp:Chart>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="WebApplication11.DecisionPoint" DeleteMethod="Remove" InsertMethod="Add" SelectMethod="ToArray" TypeName="WebApplication11.DecisionPointList"></asp:ObjectDataSource>

enter image description here

关于c# - 图表系列标签为百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31517684/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com