将StripeLine放置在系列之上(调整Z-Index / Z-Order)

时间:2012-03-14 08:32:36

标签: asp.net charts asp.net-4.0 data-visualization mschart

我正在使用System.Web.UI.DataVisualization.Charting构建柱形图,并希望显示虚线来表示平均值。 StripeLine似乎正是我正在寻找的,除了它位于列的下方/后面(参见示例)。

有没有办法调整StripeLine的“Z-Index”,以便它显示在Series的前面/上面?

我没有看到此属性,并且更改我添加SeriesStripeLine的顺序没有任何区别。

Sample Chart

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

您只需使用条纹

的text属性即可
  

Chart1.ChartAreas(“ChartArea1”)。AxisY.StripLines(0).Text =“Line   标题“