[Zedgraph] Kurve als Spline darstellen

double[] x = { 0, 10, 20, 30, 40, 50 };
double[] y = { 10, 1, 5, 0, 9, 8 };

LineItem curve = myPane.AddCurve("Spline", x, y, Color.Blue, SymbolType.Diamond );
curve.Symbol.Fill = new Fill(Color.White);
curve.Symbol.Size = 3;
curve.Line.IsSmooth = true; // Splinedarstellung einschalten
curve.Line.SmoothTension = 0.5F; // "Kurvigkeit" festlegen

[Zedgraph] Horizontales Band (Bereich) anzeigen

// rotes Band bei y=120, Höhe 20
BoxObj boxred = new BoxObj(0, 120, 1, 20, Color.Empty, Color.FromArgb(150, Color.LightCoral));
boxred.Fill = new Fill(Color.White, Color.FromArgb(200, Color.LightCoral), 45.0F);
boxred.ZOrder = ZOrder.E_BehindCurves; // Box hinter den Kurven
 // die Box erstreckt sich über den gesamten Definitionsbereich und wird an den Kanten abgeschnitten, egal wie gezoomt oder gescrollt wird
boxred.IsClippedToChartRect = true;
// die Skale für die Positionierung orientiert sich an der y-Achse
// für den Fall, dass die y2 Achse als Basis genommen werden soll, muss CoordType.XChartFractionY2Scale genommen werden
boxred.Location.CoordinateFrame = CoordType.XChartFractionYScale;
zgc.GraphPane.GraphObjList.Add(boxred);

// Text rechts im roten Band bei y=110
TextObj textred = new TextObj("Rot", 0.95f, 110, CoordType.AxisXYScale, AlignH.Right, AlignV.Center);
textred.FontSpec.Fill.IsVisible = false;
textred.FontSpec.Border.IsVisible = false;
textred.FontSpec.IsBold = true;
textred.FontSpec.IsItalic = true;
textred.FontSpec.Size = 10;
textred.Location.CoordinateFrame = CoordType.XChartFractionYScale;
textred.IsClippedToChartRect = true;
zgc.GraphPane.GraphObjList.Add(textred);

// grünes Band bei y=100, Höhe 30
BoxObj boxgreen = new BoxObj(0, 100, 1, 30, Color.Empty, Color.FromArgb(150, Color.LightGreen));
boxgreen.Fill = new Fill(Color.White, Color.FromArgb(200, Color.LightGreen), 45.0F);
boxgreen.ZOrder = ZOrder.E_BehindCurves;
boxgreen.IsClippedToChartRect = true;
boxgreen.Location.CoordinateFrame = CoordType.XChartFractionYScale;
zgc.GraphPane.GraphObjList.Add(boxgreen);

// Text rechts im grünen Band bei y=85
TextObj textgreen = new TextObj("Grün", 0.95f, 85, CoordType.AxisXYScale, AlignH.Right, AlignV.Center);
textgreen.FontSpec.Fill.IsVisible = false;
textgreen.FontSpec.Border.IsVisible = false;
textgreen.FontSpec.IsBold = true;
textgreen.FontSpec.IsItalic = true;
textgreen.FontSpec.Size = 10;
textgreen.Location.CoordinateFrame = CoordType.XChartFractionYScale;
textgreen.IsClippedToChartRect = true;
zgc.GraphPane.GraphObjList.Add(textgreen);

[Zedgraph] Textobjekt (Label) einfügen

TextObj text = new TextObj("Zeile1\nZeile2\nZeile3", 0.2F, 0.5F, CoordType.PaneFraction);

text.Location.AlignH = AlignH.Center;
text.Location.AlignV = AlignV.Center;
text.FontSpec.Border.IsVisible = false; // ohne Rahmen
text.FontSpec.Fill = new Fill(Color.White, Color.Blue, 45F);
text.FontSpec.StringAlignment = StringAlignment.Center;

zedGraph.GraphPane.GraphObjList.Add(text);

[Zedgraph] MouseMove akt. Mausposition ausgeben

private void zedGraph_MouseMove(object sender, MouseEventArgs e)
{
    PointF mousePt = new PointF(e.X, e.Y);
            
    GraphPane gpMousePane = zedGraph.MasterPane.FindChartRect(mousePt);

    if (gpMousePane != null)
    {
        double x;
        double y;

        gpMousePane.ReverseTransform(mousePt, out x, out y);

        // slXY ist ein ToolStripStatusLabel auf einem StatusStrip
        slXY.Text = "Zeit: " + DateTime.FromOADate(x).ToString("dd.MM.yyyy HH:mm:ss:fff") + ", Wert: " + y.ToString("f2");
    }
    else
    {
        slXY.Text = string.Empty;
    }
}

[Zedgraph] Legende positionieren

GraphPane myPane = zedGraph.GraphPane;

myPane.Legend.IsVisible = true;
myPane.Legend.Position = LegendPos.Float; // freie Positionierung
myPane.Legend.Location = new Location(0.98f, 0.02f, CoordType.PaneFraction, AlignH.Right, AlignV.Top); // rechts oben in der Ecke
myPane.Legend.Fill.Color = Color.White;
myPane.Legend.FontSpec.Size = 10;
myPane.Legend.IsHStack = false; // Bezeichner untereinander

[Zedgraph] eigenes Scalenformat für die x- und y-Achse festlegen

// für die X-Achse
zedGraph.GraphPane.XAxis.ScaleFormatEvent += new Axis.ScaleFormatHandler(XAxis_ScaleFormatEvent); 
 
public string XAxis_ScaleFormatEvent(GraphPane pane, Axis axis, double val, int index) 
{
    return val.ToString("f1") + " kg";
}

// für die Y-Achse
zedGraph.GraphPane.YAxis.ScaleFormatEvent += new Axis.ScaleFormatHandler(YAxis_ScaleFormatEvent); 
 
string YAxis_ScaleFormatEvent(GraphPane pane, Axis axis, double val, int index)
{
    // mit Tausender-Trennzeichen und zwei Nachkommastellen
    return val.ToString("n2");
}

// für den Titel der Y-Achse, da bei großen Zahlen häufig an den Standardtitel ein (10^3) angehangen wird
zedGraph.GraphPane.YAxis.ScaleTitleEvent += new Axis.ScaleTitleEventHandler(YAxis_ScaleTitleEvent);

string YAxis_ScaleTitleEvent(Axis axis)
{
    return "Wert [€]";
}

[Zedgraph] lineare Regression

// beliebige Kurve erzeugen
ZedGraph.PointPairList pplValues = new ZedGraph.PointPairList();

pplValues.Add(1.0, 2.0);
pplValues.Add(1.5, 0.5);
pplValues.Add(2.0, 1.0);
pplValues.Add(2.5, 4.0);

// Regression über die Kurvenpunkte durchführen und Punkte der Regressionsgerade in pplReg speichern
ZedGraph.PointPairList pplReg = pplTemp.LinearRegression(pplValues, pplValues.Count);

// Kurve zeichnen
ZedGraph.LineItem liLineValues = zedGraph.GraphPane.AddCurve("Values", pplValues, Color.Red, SymbolType.Circle);

// Regressionsgerade zeichnen
ZedGraph.LineItem liReg = zedGraph.GraphPane.AddCurve("Regression", pplReg, Color.Green, SymbolType.None);