owchart证券图形控件学习:如何加载通达信日线数据?

源码

public Form1()
        {
            InitializeComponent();

            Chart chart = new Chart();  //创建K线
            chart.Dock = DockStyle.Fill;  //设置填充          
            Controls.Add(chart);   //添加控件

            //设置显示左轴的宽度
            chart.LeftYScaleWidth = 100; 
            //设置K线的间隔   
            chart.XScalePixel = 20;  

            //添加第一个层,占100%   
            ChartDiv div1 = chart.AddChartDiv(70);
            //开盘价=0,最高价=1,最低价=2,收盘价=3
            int openField = 0;
            int highField = 1;
            int lowField = 2;
            int closeField = 3;
            //添加K线
            CandleShape candleShape = chart.AddCandle("K线", openField, highField, lowField, closeField, div1);


            //添加第二个层,占30%            
            ChartDiv div2 = chart.AddChartDiv(30);
            //声明成交量字段
            int volField = 4;
            //添加K线
            BarShape barShape = chart.AddBar("成交量", volField, div2);


            //获取数据源 
            CTableEx dataSource = chart.DataSource;

            candleShape.StyleField = CTableEx.AutoField;
            candleShape.ColorField = CTableEx.AutoField;
            dataSource.AddColumn(candleShape.StyleField);
            dataSource.AddColumn(candleShape.ColorField);

            //读取文件,并填充数据
            String filePath = Application.StartupPath + "\\SH600000.txt";
            String content = File.ReadAllText(filePath, Encoding.Default);
            String[] strs = content.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            int strsSize = strs.Length;
            for (int i = 2; i < strs.Length - 1; i++)
            {
                String str = strs[i];
                String[] subStrs = str.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                double date = (Convert.ToDateTime(subStrs[0]) - new DateTime(1970, 1, 1)).TotalSeconds;
                double open = Convert.ToDouble(subStrs[1]);
                double high = Convert.ToDouble(subStrs[2]);
                double low = Convert.ToDouble(subStrs[3]);
                double close = Convert.ToDouble(subStrs[4]);
                double volume = Convert.ToDouble(subStrs[5]);
                double amount = Convert.ToDouble(subStrs[6]);
                dataSource.Set(date, openField, open);
                dataSource.Set(date, highField, high);
                dataSource.Set(date, lowField, low);
                dataSource.Set(date, closeField, close);
                dataSource.Set(date, volField, volume);
            }

            //刷新图像  
            chart.RefreshGraph();
        }
View Code

问题

还是会出现,按最大化按钮时,应用会挂死的问题。后来发现,如果先把图形缩小(鼠标滚轮向下,或者按ArrowDown键),再按最大化按钮就没有问题了。

界面

posted @ 2021-03-08 14:33  顺其自然,道法自然  阅读(354)  评论(0编辑  收藏  举报