C# Zedgraph ,图形跳跃
C# Zedgraph , graphs jumping
我正在使用 C# 和 ZedGraph 库绘制时间和温度之间的图表。输入值是从文本文件中读取的。图形曲线预计会进步,但由于曲线不是进步的,它来回移动与 points.But 无关,点在图中正确绘制。
这是我的代码..
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();
}
示例数据类:
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 列包含温度
终于找到了,不得不设置
curve.Line.IsSmooth = false;
(或)完全删除行
curve.Line.IsSmooth = true;
我正在使用 C# 和 ZedGraph 库绘制时间和温度之间的图表。输入值是从文本文件中读取的。图形曲线预计会进步,但由于曲线不是进步的,它来回移动与 points.But 无关,点在图中正确绘制。
这是我的代码..
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();
}
示例数据类:
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 列包含温度
终于找到了,不得不设置
curve.Line.IsSmooth = false;
(或)完全删除行
curve.Line.IsSmooth = true;