1

I'm building a Column chart with System.Web.UI.DataVisualization.Charting and would like to show a dotted line to represent an average. StripeLine seems to be exactly what I'm looking for except it sits under/behind the columns (see example).

Is there a way to adjust the "Z-Index" of a StripeLine so that it is shown in front of/on top of the Series?

I don't see a property for this and changing the order I add the Series and StripeLine doesn't make a difference.

Sample Chart

Greg
  • 8,574
  • 21
  • 67
  • 109
  • It doesn't look like you can... All I see is the Z-order for StripLines, and it's determined programmatically: "The Z-order of StripLine objects is determined by their order of occurrence in the StripLinesCollection object. This means that the first occurrence is drawn first; the second occurrence is drawn second, and so on." I think they have their own separate order that is always behind the chart area – tedski Mar 14 '12 at 12:41

2 Answers2

7

You can use Annotations

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 Code

<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>

Code for Text Annotation

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);

You can get more information here

More Information About Annotations

Chart Image

Quantbuff
  • 827
  • 7
  • 9
0

You can just use the text property of the stripeline

Chart1.ChartAreas("ChartArea1").AxisY.StripLines(0).Text = "Line Title"

Joe Stellato
  • 558
  • 9
  • 31