Place StripeLine On Top of Series (Adjust Z-Index/Z-Order)

前端 未结 2 1531
孤独总比滥情好
孤独总比滥情好 2021-01-23 16:06

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 exac

2条回答
  •  梦谈多话
    2021-01-23 16:37

    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

    
        
        
        
          
                 
                
                    
                    
                    
                
                                       
           
    
    

    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

提交回复
热议问题