C# 以百分比表示的图表系列标签
我正在通过System.Web.UI.DataVisualization.Charting使用MS Visual Studio 2010中的图表组件。我在柱状图中遇到了问题,我想在柱状图中以百分比的形式显示标签。该图显示了全年中每个月的决策数量(正-绿色、负-红色、中性-蓝色)。问题是如果我使用以下命令C# 以百分比表示的图表系列标签,c#,asp.net,.net,charts,mschart,C#,Asp.net,.net,Charts,Mschart,我正在通过System.Web.UI.DataVisualization.Charting使用MS Visual Studio 2010中的图表组件。我在柱状图中遇到了问题,我想在柱状图中以百分比的形式显示标签。该图显示了全年中每个月的决策数量(正-绿色、负-红色、中性-蓝色)。问题是如果我使用以下命令 ChartDecisionDyn.Series["Positive"].IsValueShownAsLabel = true; ChartDecisionDyn.Series["Positive
ChartDecisionDyn.Series["Positive"].IsValueShownAsLabel = true;
ChartDecisionDyn.Series["Positive"].Label = "#PERCENT";
…我没有得到假定的百分比结果。结果显示了某个月的积极决策数量/全年的积极决策数量,但我希望的结果是某个月的积极决策数量/某个月的总决策数量。有人有什么建议吗?提前感谢您的帮助
您可以查看我的图形的详细信息使用
ChartDecisionDyn.Series[“正”]。LabelFormat
类似ChartDecisionDyn.Series[“正”]。LabelFormat=“#.00′%”代码>我的理解是,这些选项是相互排斥的。第二个将覆盖第一个。如何设置IsValueShownAsLabel=true
并设置正点的值=正/(正+负+中性)*100
或者设置series
Label=“#Label”
并在添加点的值时,将点的标签添加为等于正/(正+负+中性)*100
的字符串无法看到图表的图像,但我这样做了:
<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>
得到这个:
编辑:这个怎么样:
<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>
编辑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>
在我看来,这不是一个放图片的好地方!我为这张照片感到抱歉,我想出了一个更好的方法来储存这张照片。您可以看到此处描述的图表。我希望绿色栏上的标签显示的是5月的40%,6月的67%,7月的100%。谢谢你的建议,我试过了,不过,现在看起来也很感谢你。jstreet,不过这只改变了Y轴以显示百分比。。。我希望它仍然是一个值,但是在特定的环境中显示标签作为总决策的百分比month@duwen_blade不确定哪个“标签”应该是百分比或数字,但现在看看。@duwen_blade基本上我用“P0”表示百分比,“F2”表示普通数字。你可以很容易地在Y轴和系列标签之间切换,以得到你想要的。谢谢,这有点帮助,但问题是,我在图表中使用了多个系列。如果我将标签显示为一个百分比(比如P0),那么百分比将从整个图形(所有系列)中计算出来。我只需要从1级开始计算。我找到了一个更好的存储图像的方法,所以也许可以帮助了解我的意思
<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>