2015-07-20 212 views
2

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

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

...我不应该得到的百分比结果。结果显示,某些月份的正面决策数量/一年中的正面决策数量,但我期望的结果是某月份的正面决策数量/某月份的总决策数量。有没有人有任何建议?预先感谢您的帮助。

你可以看到我的图here

+0

不是一个迷人的地方,把图像,IMO! – TaW

+0

对于这个形象我很抱歉,我找到了一个更好的方式来存储图像。你可以看到这里描述的图表[链接](http://tojeale.borec.cz/help.png)。我想要绿色专栏上的标签显示的是5月份的40%,6月份的67%和7月份的100% –

回答

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> 

OR这样的:

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

+0

谢谢jstreet,但是只改变了Y轴来显示一个百分比......我想仍然将它作为一个值,但要将标签显示为在某个月的总决策的百分比 –

+0

@duwen_blade不知道哪个“标签”应该是百分比或数字,但现在看看。 – jsanalytics

+0

@duwen_blade基本上我使用百分号为“P0”,为普通数字使用“F2”。您可以轻松地在Y轴和系列标签之间切换它们以获取您想要的内容。 – jsanalytics

1

使用ChartDecisionDyn.Series["Positive"].LabelFormat的细节,如ChartDecisionDyn.Series["Positive"].LabelFormat="#.00′ %'";

+0

谢谢rt2800您的建议,但我试过了,但现在看起来像[this](http:///tojeale.borec.cz/help2.PNG) –

0

我的理解是,这些选项是互斥的。第二个会覆盖第一个。如何设置IsValueShownAsLabel=true并设定积极的心态=positive/(positive+negative+neutral)*100

或一组系列Label="#LABEL"的价值,并增加该点的值也添加点的标签等于positive/(positive+negative+neutral)*100作为一个字符串时