2011-06-07 72 views
1

我在ASP.NET C#中有一個數據綁定圖表。其中一個數據綁定字段是文本,另一個是值。我希望圖例顯示餅圖的文本,並且我希望確定圖表的形成方式,並在每個餅圖上顯示爲標籤。ASP.NET圖表 - 數據綁定值,自定義標籤

這裏是我到目前爲止的代碼:

 <asp:Chart ID="consignedChart" runat="server" DataSourceID="SqlDataSource4" 
        BackColor="LightSlateGray" Palette="None" 
        PaletteCustomColors="LightSeaGreen; SteelBlue" Width="400px" > 
        <Series> 
         <asp:Series Name="Series1" ChartType="Pie" XValueMember="Owner" 
          YValueMembers="TotalValue" Legend="Legend1" > 
         </asp:Series> 
        </Series> 
        <ChartAreas> 
       <asp:ChartArea Name="ChartArea1" Area3DStyle-Enable3D="true" BackColor="LightSlateGray"> 
          <Area3DStyle Enable3D="True" LightStyle="Realistic"/> 
         </asp:ChartArea> 
        </ChartAreas> 
        <Legends> 
         <asp:Legend Name="Legend1"> 
         </asp:Legend> 
        </Legends> 
     </asp:Chart> 

編輯

這裏是一個圖像,它可能更容易理解。紅色框中的標籤是我想要更改以顯示數值的標籤。

chart

回答

1

我知道這個答案可能出現一個有點晚了,請不要炒我爲:)

我不知道你如何綁定你的數據,但我下載安裝了Windows Forms Samples Environment的Microsoft Chart,我可以從中學到很多東西。

這裏是一個鏈接,你也可以從MSDN archives獲得asp.net樣本。

我也在使用ILSpy查看System.Windows.Forms.DataVisualization.Charting命名空間中的代碼。這樣你可以找到很多無證的東西。

最後,這裏的一些WinForm的代碼示例,從中可以得出一些想法爲你的問題,然後在asp.net標記寫:

using System.Windows.Forms.DataVisualization.Charting; 
... 

// Show data points values as labels 
chart1.Series["Series1"].IsValueShownAsLabel = true; 

// Set axis label 
chart1.Series["Series1"].Points[2].AxisLabel = "My Axis Label\nLabel Line #2"; 

// Set data point label 
chart1.Series["Series1"].Points[2].Label = "My Point Label\nLabel Line #2"; 

希望有所幫助。

+0

我真的切換到Telerik控件,並解決了他們的控制問題,但感謝您的帖子,似乎回答我的問題。 – Will 2011-07-29 20:22:05