gpt4 book ai didi

c# - ZedGraph 规模都搞砸了

转载 作者:太空宇宙 更新时间:2023-11-03 14:07:45 25 4
gpt4 key购买 nike

使用 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.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);

是否需要将日期解析为 OADate?如果你将它设为 XDate,你可以将它用作 double

XDate tm = rdr.GetDateTime("price_datetime");
double bid = rdr.GetDouble("bid");
lst.Add((double)tm, bid);

关于c# - ZedGraph 规模都搞砸了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8874725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com