在 C# 中用 DataPointCollection.DataBindY 绘制股票图表

Drawing stock chart with DataPointCollection.DataBindY in C#

如何同时使用 List<> 和 DataPointCollection.DataBindY 绘制股票图表?

我知道如何在图表上添加股票数据,但我不想通过添加循环和重复绘图,因为实际列表要长得多。

为了立即绘制图表,我尝试了 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, 0, 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[] 表示一个列表数组。

private void button1_Click(object sender, EventArgs e)
{
    List<double>[] Lists = new List<double>[4];

    for (int i = 0; i < 4; i++)
    {
        Lists[i] = new List<double>();
    }

    Lists[0].Add(5); // high
    Lists[0].Add(10);

    Lists[1].Add(0); // low
    Lists[1].Add(5);

    Lists[2].Add(3); // close
    Lists[2].Add(8);

    Lists[3].Add(2); // open
    Lists[3].Add(7);

    chart1.Series[0].Points.DataBindY(Lists);
}