I have a set of points on which I build a closed area. I use C # Chart SeriesType: Line. It looks like this:

Chart line

I need to paint over this area. I did not find a standard Series (the closest is Area, but it paints the area all the way to 0 in y).

Thanks in advance for the answers and suggestions.

  • If you did not find a suitable type of chart among the standard ones, then the standard Chart control does not know how. He generally has little ability. - rdorn
  • Not sure I understood correctly what you want to get - user227049
  • @FoggyFinder need to get a custom schedule with a shaded closed area. Standard Chart is not able to. The control code is closed, in any case, it is not on the refferncesource, so even looking at what you need to inherit and override will not work, there is no such thing in the docks. So it's dull, it's easier to draw the graph yourself on the Panel. It is possible to search in third-party libraries, but most likely it is useless, a non-standard solution is needed, and in ready-made controls only more or less standard things exist and not all - rdorn

1 answer 1

With the Chart component, as with WindowsForms in general, I worked very little, but the search for information on your subject led to one of the solutions.

Pick up all the points that define your shape in the GraphicsPath , and then display them using Graphics.FillPath

Example:

  Series some = new Series("Some"); some.ChartType = SeriesChartType.Line; some.Color = Color.Red; some.BorderWidth = 3; //коллекция точек some.Points.AddXY(10, 10); some.Points.AddXY(40, 10); some.Points.AddXY(40, 60); some.Points.AddXY(40, 70); some.Points.AddXY(10, 60); some.Points.AddXY(10, 10); chart.Series.Add(some); 

...

  private void Chart_Paint(object sender, PaintEventArgs e) { var graphics = e.Graphics; GraphicsPath gp = new GraphicsPath(FillMode.Winding); Axis ax = chart.ChartAreas[0].AxisX; Axis ay = chart.ChartAreas[0].AxisY; PointF[] points = chart .Series["Some"] .Points .Select(x => new PointF { X = (float)ax.ValueToPixelPosition(x.XValue), Y = (float)ay.ValueToPixelPosition(x.YValues[0]) }) .ToArray(); gp.AddLines(points); using (SolidBrush brush = new SolidBrush(Color.Green)) graphics.FillPath(brush, gp); gp.Dispose(); } 

Result:

enter image description here