我通过System.Web.UI.DataVisualization.Charting在MS Visual Studio 2010中使用Chart组件。我在列图中遇到问题,我希望将标签显示为百分比。该图表显示了整个一年中每个月的决策数量(正 - 绿色,负 - 红色,中性 - 蓝色)。麻烦的是,如果我使用以下命令...
ChartDecisionDyn.Series["Positive"].IsValueShownAsLabel = true;
ChartDecisionDyn.Series["Positive"].Label = "#PERCENT";
......我没有得到百分比结果。结果显示全年某些月份/正面决策数量的正面决策数量,但我希望的结果是特定月份的正面决策数量/某个月的总决策数量。有没有人有任何建议?在此先感谢您的帮助。
您可以查看我的图表here
的详细信息答案 0 :(得分:2)
看不到图表的图片,但我这样做了:
<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";
得到了这个:
编辑:这个怎么样:
<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>
答案 1 :(得分:1)
使用ChartDecisionDyn.Series["Positive"].LabelFormat
等ChartDecisionDyn.Series["Positive"].LabelFormat="#.00′ %'";
答案 2 :(得分:0)
我的理解是这些选择是相互排斥的。第二个将覆盖第一个。如何设置IsValueShownAsLabel=true
并设置正值=positive/(positive+negative+neutral)*100
或设置系列Label="#LABEL"
,当添加点的值时,还要将点的标签添加为positive/(positive+negative+neutral)*100
作为字符串