C# ZedGraph的比例都搞砸了
使用ZedGraph显示随时间变化的价格。显然,我在设置图表时出错了。有什么想法吗 这是我正在做的代码C# ZedGraph的比例都搞砸了,c#,charts,zedgraph,C#,Charts,Zedgraph,使用ZedGraph显示随时间变化的价格。显然,我在设置图表时出错了。有什么想法吗 这是我正在做的代码 private void Form1_Load(object sender, EventArgs e) { myPane = zgc.GraphPane; // Set the Titles myPane.Title.Text = "Forex"; myPane.XAxis.Title.Text = "Date/Time"; myPane.YAxis.
private void Form1_Load(object sender, EventArgs e)
{
myPane = zgc.GraphPane;
// Set the Titles
myPane.Title.Text = "Forex";
myPane.XAxis.Title.Text = "Date/Time";
myPane.YAxis.Title.Text = "Price";
myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.Scale.MajorUnit = DateUnit.Minute;
myPane.XAxis.Scale.Format = "T";
}
private void QueryDB(ref PointPairList lst)
{
if (connection == null)
connection = new MySql.Data.MySqlClient.MySqlConnection(connStr);
try
{
if (connection.State == ConnectionState.Closed)
connection.Open();
string pair = cboPair.Text;
string sql = "SELECT bid, ask, price_datetime FROM forex.prices WHERE pair='" + pair + "' and price_datetime > (NOW() - INTERVAL 1 MINUTE) ORDER BY price_datetime desc;";
MySqlCommand cmd = new MySqlCommand(sql, connection);
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
DateTime tm = rdr.GetDateTime("price_datetime");
double bid = rdr.GetDouble("bid");
lst.Add(tm.ToOADate(), bid);
}
rdr.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
}
}
private void cmdRefresh_Click(object sender, EventArgs e)
{
PointPairList bidPrice = new PointPairList();
QueryDB(ref bidPrice);
LineItem myCurve = myPane.AddCurve("Bid", bidPrice, Color.Red);
myPane.YAxis.Scale.MinAuto = true;
myPane.YAxis.Scale.MaxAuto = true;
myPane.XAxis.Scale.MinAuto = true;
myPane.XAxis.Scale.MaxAuto = true;
zgc.AxisChange();
// just points not lines. bigger points and colored based on
// buy or sell. red for sell, green for buy
//PointPairList tradeEntries = new PointPairList();
}
在阅读了您的代码后,我发现一段代码与zedgraph的含义不符
lst.Add(tm.ToOADate(), bid);
您需要解析要加载的日期吗?如果您将其设为XDate,则可以将其用作double
XDate tm = rdr.GetDateTime("price_datetime");
double bid = rdr.GetDouble("bid");
lst.Add((double)tm, bid);
一个选项是使用不同的轴类型: myPane.XAxis.Type=AxisType.DateAsOrdinal->而不是AxisType.Date 这意味着图形上的所有点将在X轴上均匀分布。 ZedGraph不会使用日期/时间来确定点的X值, 但您仍然可以看到它(工具提示,可能也在轴标签上) 除此之外,可能还需要将myPane.XAxis.Scale.MinorUnit设置为DateUnit。其次,我不知道 祝你好运