问题描述
如何同时使用 List 和 DataPointCollection.DataBindY 绘制股票图表?
我知道如何在图表上添加股票数据,但我不想通过 Add 循环和重复绘制,因为实际列表要长得多。
为了立即绘制图表,我尝试了 DataPointCollection.DataBindY 但它不起作用。它需要 IEnumerable[] 但我不知道如何将 List 更改为 IEnumerable[]。
public partial class Form1 : Form
{
double[] Candle;
List<double[]> CandleList = new List<double[]>();
public Form1()
{
InitializeComponent();
Candle = new double[] { 5,3,1 };
CandleList.Add(Candle);
Candle = new double[] { 10,5,7,9 };
CandleList.Add(Candle);
}
private void button1_Click(object sender,EventArgs e)
{
for (int i = 0; i < CandleList.Count; i++)
{
chart1.Series[0].Points.Add(CandleList[i]); // works well
}
}
private void button2_Click(object sender,EventArgs e)
{
chart1.Series[0].Points.DataBindY(CandleList); // System.ArgumentException
}
}
解决方法
因为列表是一个 iEnumerable,所以 iEnumerable[] 表示一个列表数组。
def main():
n = 132189
l = []
total = 0
for i in range((len(str(n)))):
g = str(n)
#print(int(g[i]))
total += int(g[i])
tot = 0
for j in range(len(str(total))):
f = str(total)
#print(int(f[j]))
tot += int(f[j])
if tot > 9:
continue
else:
l.append(tot)
#print(tot,'tot')
print(l[-1]) # print(max(l))
print(l,end='') # not the best,but it works.