2010-04-21 63 views
5

我正在使用Microsoft圖表控件創建一個三維圖表。以下是圖像:使用Microsoft圖表控件的圖表上的標籤

alt text http://www.highoncoding.com/articleimages/bar_graph.png

我想告訴每個條形圖的頂部點。像在條形圖的頂部考試1它應該顯示2(在2分)等

下面是代碼:

private void BindData() { 

      var exams = new List<Exam>() 
      { 
       new Exam() { Name = "Exam 1", Point = 10 }, 
       new Exam() { Name = "Exam 2", Point = 12 }, 
       new Exam() { Name = "Exam 3", Point = 15 }, 
       new Exam() { Name = "Exam 4", Point = 2 } 
      }; 

      var series = ExamsChart.Series["ExamSeries"];   



      series.YValueMembers = "Point"; 
      series.XValueMember = "Name"; 

      //series.MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Circle; 
      //series.MarkerSize = 20; 
      //series.LegendText = "hellow"; 
      //series.Label = "something";    


      var chartAreas = ExamsChart.ChartAreas["ChartArea1"];   


      ExamsChart.DataSource = exams; 
      ExamsChart.DataBind(); 
     } 

這裏是html代碼:

<asp:Chart ID="ExamsChart" Width="600" Height="320" runat="server"> 
     <Titles> 
     <asp:Title Text="Exam Report" /> 
     </Titles> 
     <Series> 
      <asp:Series Name="ExamSeries" ChartType="Column"> 
      </asp:Series> 
     </Series> 
     <ChartAreas> 

      <asp:ChartArea Name="ChartArea1"> 
      <Area3DStyle Enable3D="true" WallWidth="10" /> 
      </asp:ChartArea> 
     </ChartAreas> 
     </asp:Chart> 

UPDATE:

下面是答案:

foreach (var exam in exams) { 

       var point = new DataPoint(); 
       point.SetValueXY(exam.Name, exam.Point); 

       point.Label = exam.Name; 

       series.Points.Add(point); 
      } 

回答

1

直接從MS圖表中取樣:

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

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