How do I fill everything over a straight line and under a curve?

Dead Girl

I am using the Charts component in Windows Forms.

I create a straight line using

chart1.Series["Grenzwert"].Points.Add(new DataPoint(0, y));
chart1.Series["Grenzwert"].Points.Add(new DataPoint(maxwidth, y));

Also I plot a a series of points connected by a line, let's call it curve.

How do I show everything over straight line and under curve filled?

Column fills the whole area, not just above straight line.

Example:

enter image description here

user3093781

I have an idea that use SeriesChartType.Range as follow.

private void UpdateChart(float straight_line, List<DataPoint> curve)
{
    float y = straight_line;    // YValue of the straight line
    var list = curve.ToList();  // Clone the curve

    int count = list.Count - 2;

    for (int i = 0; i < count; i++)  // Calculate intersection point between the straight line and a line between (x0,y0) and (x1,y1) 
    {
        double x0 = list[i + 0].XValue;
        double y0 = list[i + 0].YValues[0];
        double x1 = list[i + 1].XValue;
        double y1 = list[i + 1].YValues[0];

        if ((y0 > y && y1 < y) || (y0 < y && y1 > y))
        {
            double x = (y - y0) * (x1 - x0) / (y1 - y0) + x0;

            list.Add(new DataPoint(x, y));
        }
    }

    list.Sort((a, b) => Math.Sign(a.XValue - b.XValue));

    chart1.Series[0].Points.Clear();
    chart1.Series[0].ChartType = SeriesChartType.Range;
    chart1.Series[0].Color = Color.Red;
    chart1.Series[0].BorderColor = Color.Cyan;
    chart1.ChartAreas[0].AxisX.Minimum = 0;
    chart1.ChartAreas[0].AxisX.Interval = 1;

    for (int i = 0; i < list.Count; i++)
    {
        double xx = list[i].XValue;
        double yy = list[i].YValues[0];
        if (yy > y)
        {
            chart1.Series[0].Points.AddXY(xx, y, yy);
        }
        else
        {
            chart1.Series[0].Points.AddXY(xx, yy, yy);
        }
    }

    chart1.ChartAreas[0].AxisY.StripLines.Add(new StripLine { IntervalOffset = y, Interval = 0, BorderColor = Color.Orange, BorderWidth = 2 });

}

As in the below drawing to judge whether the straight line and a line between (x0,y0) and (x1,y1) intersect, case 1 is (y0 < y && y1 > y) and case 2 is (y0 > y && y1 < y) . In case 1 and case 2, they intersect each other. In case 3 and case 4, they don't intersect each other.

the below drawing to judge whether the straight line and a line between (x0,y0) and (x1,y1) intersect

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Fill under line curve

From Dev

How can I make straight line instead of curve line in d3 force layout?

From Java

How do I get a curve point on a line?

From Dev

How to fit straight line to variable curve and determining the x-intercept

From Dev

Plotting normal curve over histogram using ggplot2: Code produces straight line at 0

From Dev

How do I check if the line is over?

From Dev

How do I extract everything from the start of a line to a specific string?

From Dev

How do I get the total size of everything in a directory in one line?

From Dev

SVG Path: Curve tailing off of a straight line

From Dev

How to fill rainbow color under a curve in Python matplotlib

From Dev

How to fill area under curve in seaborn distribution plot

From Dev

How do I make a function that fires a bullet from the gun in a straight line to the right in c#?

From Dev

How to fill olny curve up to a certain value gnuplot simultaneously with line

From Dev

How do I loop over each line inside a file with ansible?

From Dev

In scilab how do you plot sin as a curve rather than as straight lines?

From Dev

How can I draw a straight line using ZingChart?

From Dev

Plot straight line over a interval in MATLAB

From Dev

In d3, how do I apply a style to my line chart for both the line and the area under the line?

From Dev

How do I delete everything in /var/mail/username from the command line?

From Dev

How do I delete everything after second occurrence of quotes using the command line?

From Dev

Fitting a straight line to a log-log curve in matplotlib

From Dev

Draw a curve connecting two points instead of a straight line

From Dev

How do I create a 'Parallelogram' shape in css with a straight side?

From Java

How do I delete everything in Redis?

From Dev

How do I remove everything except price?

From Dev

How do I upgrade everything on Ubuntu

From Dev

How do I pause everything running on a webpage?

From Dev

How can I configure everything under an ExpandBar to follow it as it expands / collapses?

From Dev

Android GraphView - how to fill area under the Line Graph with color?

Related Related

  1. 1

    Fill under line curve

  2. 2

    How can I make straight line instead of curve line in d3 force layout?

  3. 3

    How do I get a curve point on a line?

  4. 4

    How to fit straight line to variable curve and determining the x-intercept

  5. 5

    Plotting normal curve over histogram using ggplot2: Code produces straight line at 0

  6. 6

    How do I check if the line is over?

  7. 7

    How do I extract everything from the start of a line to a specific string?

  8. 8

    How do I get the total size of everything in a directory in one line?

  9. 9

    SVG Path: Curve tailing off of a straight line

  10. 10

    How to fill rainbow color under a curve in Python matplotlib

  11. 11

    How to fill area under curve in seaborn distribution plot

  12. 12

    How do I make a function that fires a bullet from the gun in a straight line to the right in c#?

  13. 13

    How to fill olny curve up to a certain value gnuplot simultaneously with line

  14. 14

    How do I loop over each line inside a file with ansible?

  15. 15

    In scilab how do you plot sin as a curve rather than as straight lines?

  16. 16

    How can I draw a straight line using ZingChart?

  17. 17

    Plot straight line over a interval in MATLAB

  18. 18

    In d3, how do I apply a style to my line chart for both the line and the area under the line?

  19. 19

    How do I delete everything in /var/mail/username from the command line?

  20. 20

    How do I delete everything after second occurrence of quotes using the command line?

  21. 21

    Fitting a straight line to a log-log curve in matplotlib

  22. 22

    Draw a curve connecting two points instead of a straight line

  23. 23

    How do I create a 'Parallelogram' shape in css with a straight side?

  24. 24

    How do I delete everything in Redis?

  25. 25

    How do I remove everything except price?

  26. 26

    How do I upgrade everything on Ubuntu

  27. 27

    How do I pause everything running on a webpage?

  28. 28

    How can I configure everything under an ExpandBar to follow it as it expands / collapses?

  29. 29

    Android GraphView - how to fill area under the Line Graph with color?

HotTag

Archive