我正在使用C#和ZedGraph库在时间和温度之间绘制图形。输入值从文本文件中读取。预计图形曲线会有所进展,但在曲线不是渐进的情况下,曲线的前后移动与点无关。但是这些点在图中正确绘制。
这是我的代码..
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文件内容:第1列包含时间,第5列包含温度
答案 0 :(得分:1)
终于找到了,我不得不设置
curve.Line.IsSmooth = false;
(或)完全删除该行
curve.Line.IsSmooth = true;