0
我使用C#和ZedGraph庫在時間和溫度之間繪製圖形。輸入值從文本文件中讀取。圖表曲線預計會有所進展,但曲線不是漸進的,它將與點不相關,而是在圖表中正確繪製點。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列包含溫度
你嘗試過調試和觀察數據,你讀過之後,確保你已經正確解釋了一切?我看到例如你在文件中有AM/PM,這是正確的讀取和解析? –
@Karlsen。是的,我已經把調試點和檢查時間,他們正在閱讀和解釋正確。我甚至發現圖形點完全被繪製出來。它只是不是逐步移動的曲線。 – jaycyborg