2015-07-20 213 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作爲一個字符串時