当前位置:   article > 正文

通达信 day文件 解析_owchart教程六:如何加载通达信分钟线数据?

owchart目录

这是owchart框架教程的第六节,该示例兼容支持Visual Studio 2005-202X,覆盖.Net2.0到后续所有版本,不同版本的IDE项目构建和编码过程基本相同。该示例代码会被上传至git,github,百度网盘,关于owchart的介绍和下载地址,还有往期教程如下:

owchart证券图形控件 v1.0

owchart教程一:如何创建项目和添加布局?

owchart教程二:如何添加K线?

owchart教程三:如何添加成交量?

owchart教程四:如何添加趋势线?

owchart教程五:如何加载通达信日线数据?

4650119eaa97081971effe6ce33e73d2.png

如何从通达信下载数据可以参见以前的教程:

如何免费轻松获得最完整可靠的股票期货等历史数据?

本节重点讲述如何在图层中加载通达信分钟线数据,使之显示出来,包含了完整的代码示例。

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using owchart;using System.IO;namespace MyChart{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();            Chart chart = new Chart();  //创建K线                   chart.Dock = DockStyle.Fill;  //设置填充                      Controls.Add(chart);   //添加控件             //设置显示左轴的宽度            chart.LeftYScaleWidth = 100;            //设置K线的间隔            chart.XScalePixel = 20;            //添加第一个层,占70%                        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);            //设置X轴的格式                        div2.XScale.Format = "hh:mm";            //声明成交量字段            int volField = 4;            //添加K线            BarShape barShape = chart.AddBar("成交量", volField, div2);            //获取数据源            CTableEx dataSource = chart.DataSource;            //读取文件,并填充数据            String filePath = Application.StartupPath + "\\SH000001.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);                int hour = Convert.ToInt32(subStrs[1].Substring(0, 2));                int minute = Convert.ToInt32(subStrs[1].Substring(2, 2));                DateTime dayTime = Convert.ToDateTime(subStrs[0]);                double date = (new DateTime(dayTime.Year, dayTime.Month, dayTime.Day, hour, minute, 0) - new DateTime(1970, 1, 1)).TotalSeconds;                double open = Convert.ToDouble(subStrs[2]);                double high = Convert.ToDouble(subStrs[3]);                double low = Convert.ToDouble(subStrs[4]);                double close = Convert.ToDouble(subStrs[5]);                double volume = Convert.ToDouble(subStrs[6]);                double amount = Convert.ToDouble(subStrs[7]);                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();        }    }}

运行程序,显示如下图像,说明加载成功:

752e4894741ce0bed070915e3cf531e8.png

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/171119
推荐阅读