简体   繁体   中英

C# Zedgraph , graphs jumping

I am using C# and ZedGraph library to draw graph between Time and Temperature. The input values are read from a text file. The graph curve is expected to be progressing but where as the curve is not progressive , it is moving back and forth irrelevant of the points.But the points are plotted correctly in the graph.

在此处输入图片说明

Here is my code ..

  private void Form2_Load(object sender, EventArgs e)
  {
    GraphPane myPane = Gcontrol.GraphPane;

    // Set the title and axis labels
    myPane.Title.Text = "Date Time Chart";
    myPane.XAxis.Title.Text = "TimeFrame";
    myPane.YAxis.Title.Text = "Temperature";

    //List to hold Points to be plotted
    PointPairList pList = new PointPairList();

    SampleData sd = new SampleData();
    sd.getSampleData();


    for (int i = 0; i < sd.x.Count; i++)
    {
        pList.Add(sd.x[i],sd.y[i]);
    }

    LineItem curve = myPane.AddCurve("Points", pList, Color.Black, SymbolType.Diamond);
    curve.Line.IsSmooth = true;
    myPane.XAxis.Type = AxisType.Date;
    myPane.XAxis.Scale.FontSpec.Angle = 65;
    myPane.XAxis.Scale.MajorStep = 1;
    myPane.XAxis.Scale.MajorUnit = DateUnit.Hour;
    myPane.XAxis.Scale.MinorUnit = DateUnit.Hour;
    myPane.XAxis.Scale.Format = "dd-MMM-yy HH:MM";
    Gcontrol.AxisChange();

}

SampleDataClass :

class SampleData
{
    public List<double> x = new List<double>();
    public List<double> y = new List<double>();

    public void getSampleData()
    {            

        string[] lines = System.IO.File.ReadAllLines("input.txt");
        foreach (string line in lines)
        {
          x.Add(new XDate(Convert.ToDateTime(line.Split(',')[0].Trim())));                 
          y.Add(Convert.ToDouble(line.Split(',')[4].Trim()));

        }

    }
}

input.txt file contents : Column 1 contains Time and Column 5 contains Temperature

input.txt文件内容

Finally found it, I had to set

curve.Line.IsSmooth = false; 

(or) completely remove the line

curve.Line.IsSmooth = true;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM