VidarO - 2015-10-01

Hi,
I'm using Zedgraph to plot some data parsed from an XML file. The parsing and plotting of data works okay, and now I would like to use fill underneath the line in order to mark how close a value is to the limit.
My X-axis is dateAsOrdinal type, while my Y-axis contains numbers (double).

My code is shown in full below, but it is essential the code part

LineItem curve;
            curve = myPane.AddCurve(_Ansatt.Attribute("Fornavn").Value, list, Color.Black, SymbolType.Circle);
            curve.Line.Width = 1.5F;
            // Fill the area under the curve with a white-green gradient
            curve.Line.Fill = new Fill(Color.Green, Color.Red);
            curve.Line.Fill.Type = FillType.GradientByY;
            curve.Line.Fill.RangeMin = 20.0F;
            curve.Line.Fill.RangeMax = 175.0F;

I would expect to do the gradient work. The expected plot would be a gradient that changes with the Y-values, where y-values of 20 or less is given the color green, and y-Values of 175 and above is given the color Red.
The actual outcome of this code, is that the left side of the plot is green, and the right side of the plot is red. It looks like the gradient is starting on green on the first date (first x-value) date, and then fades over to red on the last X-value (Last date). I have tried with FillType.GradientByX with the exact same result.
Any tips or ideas?

Best Regards
Vidar

Full code for update plot:

private void UpdatePlot(ZedGraphControl myPlot, XElement _Ansatt)
        {
            IEnumerable<XElement> Belastning = _Ansatt.Elements("Belastning");
            IEnumerable<XElement> Prosjekter = _Ansatt.Element("Erfaring").Elements("Prosjekt");
            PointPairList list = new PointPairList();
            GraphPane myPane = myPlot.GraphPane;
            string a = Convert.ToString(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            foreach (var it in Belastning)
            {
                string Date = it.Attribute("Dato").Value;
                string[]date = Date.Split(new[] {'-'}, StringSplitOptions.RemoveEmptyEntries);
                double x = (double)new XDate(Convert.ToInt32(date[0]), Convert.ToInt32(date[1]), Convert.ToInt32(date[2]));
                string temp = it.Attribute("Belastning").Value;
                temp = temp.Replace(".", a);
                double y = Convert.ToDouble(temp);
                list.Add(x, y);

                bool exists = _Ansatt.Element("Erfaring").Elements("Prosjekt").Where(z => z.Attribute("StartDato").Value == Date).Any();
                if (exists)
                {
                    string Text ="";
                    var textElement = _Ansatt.Element("Erfaring").Elements("Prosjekt").Where(z => z.Attribute("StartDato").Value == Date);
                    foreach (var el in textElement)
                    {
                        Text += el.Attribute("Prosjekt").Value;
                        if (textElement.LongCount() > 1)//if more than one element
                        {
                            Text = Text + "\n";
                        }
                    }

                    TextObj plottext = new TextObj(Text, x, y, CoordType.AxisXYScale,AlignH.Right, AlignV.Center);
                    plottext.FontSpec.FontColor = Color.Black;
                    plottext.FontSpec.Border.Color = Color.LightGray;
                    plottext.FontSpec.Fill.Color = Color.LightGray;
                    plottext.FontSpec.Fill.IsVisible = false;
                    plottext.FontSpec.Border.IsVisible = true;
                    // tilt the text 
                    plottext.FontSpec.Angle = 45.0F;
                    plottext.FontSpec.StringAlignment = StringAlignment.Center;
                    plottext.FontSpec.Size = 10.0F;
                    myPane.GraphObjList.Add(plottext);

                }

            }

            //Clear Plot
            myPane.CurveList.Clear();
            myPlot.AxisChange();
            myPlot.Invalidate();

            LineItem curve;
            curve = myPane.AddCurve(_Ansatt.Attribute("Fornavn").Value, list, Color.Black, SymbolType.Circle);
            curve.Line.Width = 1.5F;
            // Fill the area under the curve with a white-green gradient
            curve.Line.Fill = new Fill(Color.Green, Color.Red);
            curve.Line.Fill.Type = FillType.GradientByY;
            curve.Line.Fill.RangeMin = 20.0F;
            curve.Line.Fill.RangeMax = 175.0F;

            // Make it a smooth line
            curve.Line.IsSmooth = true;
            curve.Line.SmoothTension = 0.6F;
            // Fill the symbols with white
            curve.Symbol.Fill = new Fill(Color.White);
            curve.Symbol.Size = 5;

            /*var listArray = list.ToArray();
            var Startdate = listArray[0].X;
            long lastNumber = listArray.Length;
            var EndDate = listArray[lastNumber - 1].X;
            // Add a BoxObj to show a colored band behind the graph data
            BoxObj box = new BoxObj(Startdate, 170, (EndDate - Startdate), 10,
                    Color.Empty, Color.LightPink);
            box.Location.CoordinateFrame = CoordType.AxisXYScale;
            // Align the left-top of the box to (0, 110)
            box.Location.AlignH = AlignH.Left;
            box.Location.AlignV = AlignV.Top;
            // place the box behind the axis items, so the grid is drawn on top of it
            box.ZOrder = ZOrder.A_InFront;
            myPane.GraphObjList.Add(box);*/

            myPlot.AxisChange();

        }
 

Last edit: VidarO 2015-10-01