2012-03-14 114 views
1

我正在构建一个包含System.Web.UI.DataVisualization.Charting的柱状图,并且想要显示一条虚线以表示平均值。 StripeLine似乎正是我正在寻找的东西,除了它位于列之下/之后(请参阅示例)。将StripeLine放置在系列顶部(调整Z-索引/ Z-顺序)

有没有办法调整StripeLine的“Z-Index”,使其显示在Series之前/之上?

我没有看到此属性和更改顺序我添加SeriesStripeLine没有什么区别。

Sample Chart

+0

它看起来不像你可以......我所看到的只是StripLines的Z顺序,它以编程方式确定: “StripLine对象的Z顺序由其在StripLinesCollection对象中的出现顺序决定。这意味着第一次出现是先画出来的;第二次出现是第二次,等等。“ 我认为他们有他们自己的单独的订单,总是在图表区域后面 – tedski 2012-03-14 12:41:47

回答

7

您可以使用标注

double avg = Chart1.Series[0].Points.Average(p => p.XValue); 
double lineHeight = avg; 
HorizontalLineAnnotation ann = new HorizontalLineAnnotation(); 
ann.AxisX = Chart1.ChartAreas[0].AxisX; 
ann.AxisY = Chart1.ChartAreas[0].AxisY; 
ann.IsSizeAlwaysRelative = false; 
ann.AnchorY = lineHeight; 
ann.IsInfinitive = true; 
ann.ClipToChartArea = Chart1.ChartAreas[0].Name; ann.LineColor = Color.Red; ann.LineWidth = 3; 
Chart1.Annotations.Add(ann); 

HTML代码

<asp:Chart runat="server" ID="Chart1" ImageStorageMode="UseImageLocation" Width="800px" Height="400px" OnClick="Chart1_Click"> 
    <ChartAreas > 
    <asp:ChartArea></asp:ChartArea> 
    </ChartAreas> 
    <series> 
      <asp:Series Name="Students" BorderColor="180, 26, 59, 105"> 
      <Points> 
       <asp:DataPoint AxisLabel="jon" XValue="5" YValues="4" /> 
       <asp:DataPoint AxisLabel="kon" XValue="15" YValues="44" /> 
       <asp:DataPoint AxisLabel="pol" XValue="85" YValues="90" /> 
      </Points> 
      </asp:Series>       
     </series> 
</asp:Chart> 

规范文本批注

TextAnnotation txtAnn = new TextAnnotation(); 
txtAnn.AxisX = Chart1.ChartAreas[0].AxisX; 
txtAnn.AxisY = Chart1.ChartAreas[0].AxisY; 
txtAnn.IsSizeAlwaysRelative = false; 
txtAnn.AnchorY = lineHeight; 
txtAnn.AnchorX = Chart1.Series[0].Points.Last().XValue; 
txtAnn.AnchorAlignment = ContentAlignment.BottomLeft; 
txtAnn.Text = "DivisionOne(35.5)"; 
txtAnn.ClipToChartArea = Chart1.ChartAreas[0].Name; txtAnn.ForeColor = Color.Red; 
Chart1.Annotations.Add(txtAnn); 

你可以得到更多的资料,请离子这里

More Information About Annotations

Chart Image

+0

看起来不像我可以添加标题/文本标题......虽然您的确回答我的问题,谢谢 – Greg 2012-03-15 03:36:22

+0

你可以使用文本注释 – Quantbuff 2012-03-15 04:05:09

+0

啊,谢谢,我会加油,如果你可以请添加到你的答案。 – Greg 2012-03-15 17:05:42

0

您可以只使用stripeline的文本属性

Chart1.ChartAreas( “ChartArea1”)。AxisY.StripLines(0)。文本= “行 标题”