0

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.

enter image description here

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 file contents

jaycyborg
  • 983
  • 1
  • 8
  • 15
  • Have you tried debugging and looking at the data after you've read it, to ensure you've interpreted everything correctly? I see for instance that you have AM/PM in the file, is this correctly read and parsed? – Lasse V. Karlsen May 06 '15 at 08:27
  • @Karlsen . Yes I have put debugging point and checked the time, they are being read and intepreted correctly. I even find the graph points are plotted exactly. It is just the curve which is not moving progressively. – jaycyborg May 06 '15 at 08:53

1 Answers1

1

Finally found it, I had to set

curve.Line.IsSmooth = false; 

(or) completely remove the line

curve.Line.IsSmooth = true;
jaycyborg
  • 983
  • 1
  • 8
  • 15