1. var charset = echarts.init(document.getElementById("k_line"))
  2. $.get(k_line.url_A).done(function (info) {
  3. var rawData = info.Data.History;
  4. var single = info.Data.Signal;
  5. var single_ = [];
  6. var arr = [];
  7. for (var i = 0; i < single.length; i++) {
  8. var data = single[i][0];
  9. var y = single[i][1];
  10. var origle = single[i][2];
  11. arr.push(data);
  12. var obj = {};
  13. if (origle == '0') {
  14. obj = {
  15. name: '0',
  16. coord: [data, y],
  17. symbol: k_line.buy_,
  18. symbolSize: [40, 40],
  19. label: "卖出"
  20. }
  21. } else {
  22. obj = {
  23. name: '1',
  24. coord: [data, y],
  25. symbol: k_line.sell_,
  26. symbolSize: [40, 40],
  27. label: "卖出"
  28. }
  29. }
  30. single_.push(obj)
  31. }
  32. var dates = rawData.map(function (item) {
  33. return item[0];
  34. });
  35. var data = rawData.map(function (item) {
  36. return [+item[1], +item[2], +item[5], +item[6], ];
  37. });
  38. var option = {
  39. title: {
  40. text: k_line.title,
  41. textStyle: {
  42. color: "rgba(255,255,255,0.4)",
  43. fontSize: "18"
  44. }
  45. },
  46. backgroundColor: '#000',
  47. brush: {
  48. toolbox: ['rect'],
  49. xAxisIndex: 0,
  50. inBrush: {
  51. symbolSize: '40px',
  52. color: '#000',
  53. color0: '#54FFFF',
  54. borderColor: '#FF3232',
  55. borderColor0: '#54FFFF'
  56. },
  57. outOfBrush: {
  58. color: '#000',
  59. color0: '#54FFFF',
  60. borderColor: '#FF3232',
  61. borderColor0: '#54FFFF'
  62. },
  63. z: 1000
  64. },
  65. toolbox: {
  66. color: "red",
  67. borderWidth: "10px",
  68. itemGap: 25,
  69. itemSize: 25,
  70. left: 'center',
  71. iconStyle: {
  72. normal: {
  73. color: 'red',
  74. borderType: "solid",
  75. borderColor: "red",
  76. textPosition: "left"
  77. },
  78. emphasis: {
  79. fontSize: "24px"
  80. }
  81. },
  82. feature: {
  83. brush: {
  84. title: {
  85. rect: "点击进入选中模式"
  86. },
  87. }
  88. }
  89. },
  90. tooltip: {
  91. trigger: 'axis',
  92. axisPointer: {
  93. animation: false,
  94. type: 'cross',
  95. lineStyle: {
  96. color: '#376df4',
  97. width: 2,
  98. opacity: 1
  99. }
  100. },
  101. formatter: function (params) {//鼠标在k线上显示的模态框
  102. var res = params[0].seriesName + ' ' + params[0].name;
  103. res += '<br/> 开盘 : ' + params[0].value[1];
  104. res += '<br/> 最高 : ' + params[0].value[3];
  105. res += '<br/> 收盘 : ' + params[0].value[2];
  106. res += '<br/> 最低 : ' + params[0].value[4];
  107. return res;
  108. },
  109. axisPointer: {
  110. type: "cross",
  111. crossStyle: {
  112. color: "#666",
  113. type: "solid"
  114. },
  115. },
  116. textStyle: {
  117. backgroundColor: "blue"
  118. }
  119. },
  120. xAxis: {
  121. type: 'category',
  122. data: dates,
  123. axisLine: { lineStyle: { color: 'red' } },
  124. axisLabel: {//坐标轴文本样式
  125. textStyle: {
  126. color: "red",
  127. },
  128. }
  129. },
  130. yAxis: {
  131. scale: true,
  132. position: "right",
  133. axisLine: { lineStyle: { color: 'red' } },
  134. //背景的虚线
  135. splitLine: {
  136. show: true,
  137. lineStyle: {
  138. color: "red",
  139. type: "dashed"
  140. }
  141. },
  142. axisLabel: {//坐标轴文本样式
  143. textStyle: {
  144. color: "red",
  145. }
  146. },
  147. boundaryGap: [0, 0.2]
  148. },
  149. grid: {//网格的区域 大小
  150. width: "95%",
  151. height: "100%",
  152. left: 0,
  153. bottom: 80
  154. },
  155. dataZoom: [
  156. {
  157. type: 'inside',
  158. start: 88,
  159.  
  160. }],
  161. animation: false,
  162. series: [//放跟数据相关的
  163. {
  164. type: 'candlestick',
  165. name: '日K',
  166. data: data,
  167. markPoint: {
  168. data: single_
  169. },
  170. itemStyle: {
  171. normal: {
  172. color: '#FF3232',
  173. color0: '#54FFFF',
  174. borderColor: '#FF3232',
  175. borderColor0: '#54FFFF'
  176. },
  177. emphasis: {
  178. color: '#FF3232',
  179. color0: '#54FFFF',
  180. borderColor: '#FF3232',
  181. borderColor0: '#54FFFF'
  182. }
  183. }
  184. },
  185. ]
  186. };
  187. //实现响应式
  188. window.onresize = charset.resize;
  189. //绘图
  190. charset.setOption(option);
  191.  
  192. //鼠标框选事件
  193. charset.on('brushSelected', renderBrushed);
  194. function renderBrushed(params) {
  195. var brushed = [];
  196. var brushComponent = params.batch[0];
  197. for (var sIdx = 0; sIdx < brushComponent.selected.length; sIdx++) {
  198. var rawIndices = brushComponent.selected[sIdx].dataIndex;
  199. brushed.push(rawIndices)
  200. }
  201. var start = brushed[0][0];
  202. s_ = start = rawData[start][0];//框选开始位置
  203. var end = brushed[0][brushed[0].length - 1];
  204. n_ = end = rawData[end][0];//框选结束位置
  205. var v1 = '您选择的回测的日期是:\n\n\n' + start + "--" + end + '\n\n\n点击进入回测页面';
  206. var url_1 = k_line.success_link + "?" + start + "&" + end;
  207. var v2 = '您选择的回测的日期不存在可回测数据';
  208. var v3 = "您选择的区间过大,请重新选择";
  209. var len_ = arr.length;
  210. for (var i = 0; i < len_; i++) {
  211. if (arr[i] > start && arr[i] < end) {
  212. if (getDays(end, start) > 360) {
  213. k_line.msg(v3, 'javascript:;')
  214. break;
  215. }
  216. k_line.msg(v1, url_1);
  217. break;
  218. } else {
  219. k_line.msg(v2, 'javascript:;')
  220. }
  221. }
  222. }
  223. })//画图完毕
  224. function getDays(strDateStart,strDateEnd){
  225. var strSeparator = "-"; //日期分隔符
  226. var oDate1;
  227. var oDate2;
  228. var iDays;
  229. oDate1= strDateStart.split(strSeparator);
  230. oDate2= strDateEnd.split(strSeparator);
  231. var strDateS = new Date(oDate1[0], oDate1[1]-1, oDate1[2]);
  232. var strDateE = new Date(oDate2[0], oDate2[1]-1, oDate2[2]);
  233. iDays = parseInt(Math.abs(strDateS - strDateE ) / 1000 / 60 / 60 /24)//把相差的毫秒数转换为天数
  234. return iDays;
  235. }//判断日期

  需求是通过后台给的数据去框选区间回测数据,如果超出一年了,就不让其回测了。

  1. var k_line = { //k线图对象
  2. msg: function (v, url) {//提示框函数
  3. charset.setOption({
  4. title: {
  5. backgroundColor: '#333',
  6. text: v,
  7. top: '50px',
  8. right: 0,
  9. width: '100px',
  10. height: '80px',
  11. textStyle: {
  12. fontSize: 12,
  13. color: '#fff',
  14. },
  15. link: url,
  16. target: "self",
  17. }
  18. });
  19. },
  20. url_A: "/Home/GetKLineData?code=" + nums_code + "&areaType=" + areatype,//后台接口
  21. buy_: 'image:///public/imags/gou.png', //买入图片
  22. sell_: 'image:///public/imags/sale.png',//卖出图片
  23. title: areaname_ + ':' + nums_code,
  24. success_link: 'javascript:void(0)',//框选成功后的跳转链接
  25. };
  26.  
  27. layer.open({ //打开k线图
  28. type: 1,
  29. title: 0,
  30. shade: 0.8,
  31. shadeClose: false,
  32. area: ['90%', '90%'],
  33. content: "<div style='position:relative;width:100%;height:100%;'><div id='k_line' style='width:100%;height:100%;'></div><div id='k_line_' style='width:158px;height:28px;position:absolute;right:0;top:116px;z-index:99999;cursor:pointer'></div></div>"
  34. });
  35. var s_ = "", n_ = "";
  36. $('#k_line_').on("click", function () { //关闭k线图
  37. if (s_ != '' && n_ != '') {
  38. jBcs.s_time = s_, jBcs.n_time = n_;
  39. jBcs.iSdisabled = false;
  40. layer.close(layer.index);
  41. }
  42. });

  

echarts画k线图的更多相关文章

  1. 使用ECharts画K线图

    需引入echarts.js插件,开发环境建议选择源代码版本,该版本包含了常见的警告和错误提示.下载地址 http://echarts.baidu.com/download.html 下面是代码,注释很 ...

  2. 【React】react项目引入echarts插件 K线图

    参考npm文档:https://www.npmjs.com/package/echarts-for-react 由于npm上已经有针对react项目出的echarts插件,所以在这里直接安装 第一步: ...

  3. echarts绘制k线图为什么写candlestick类型就报错

    错误提示:echarts-en.common.js:11713 Uncaught Error: Component series.candlestick not exists. Load it fir ...

  4. 功能分解——Android下画分时图与k线图有感

    最近工作极度繁忙,已经好久没有更新博客了,总感觉要是再不抽空总结总结点东西,分分钟就会被懒惰的状态给打到了.同时也希望同学们谨记,如果你已经决定要坚持某些正确的东西,比如背完某章单词,看一完本书抑或是 ...

  5. 在MPAndroidChart库K线图的基础上画均线

    CombinedChart 可以直接使用MPAndroidChart库里面提供的CombinedChart实现组合图形 Demo:CombinedChartDemo ------分割线(如果想在一个图 ...

  6. 关于k Line Chart (k线图)

    K Line Chart python实现k线图的代码,之前找过matplotlib中文文档但是画k线图的finance方法已经弃用了.所以自己在网上搜寻一下加上改编,很好的实现出k线图, 代码如下: ...

  7. 基于Echarts的股票K线图展示

    发布时间:2018-10-31   技术:javascript+html5+canvas   概述 基于echarts的股票K线图展示,只需引用单个插件,通过简单配置,导入数据,即可实现炫酷复杂的K线 ...

  8. 百度 echarts K线图使用

    看个效果图先 首先在需要插入图例的HTML中嵌入 <div id="main" style="height:400px"></div> ...

  9. K线图学习

    本博文(适合入门的股民朋友)内容来自网络,股市有风险,入市需谨慎 一.起源 K线图(Candlestick Charts)又称蜡烛图.日本线.阴阳线.棒线等,常用说法是“K线”,起源于日本十八世纪德川 ...

随机推荐

  1. js ejs for语句的第二种遍历用法

    var A = {a:1,b:2,c:3,d:"hello world"}; for(var k in A) { console.log(k,A[k]); var h = new ...

  2. LightOJ 1306 - Solutions to an Equation 裸EXGCD

    本题是极其裸的EXGCD AX+BY+C=0 给你a b c 和x与y的区间范围,问你整数解有几组 作为EXGCD入门,题目比较简单 主要需要考虑区间范围的向上.向下取整,及正负符号的问题 问题是这正 ...

  3. 奇偶排序Odd-even sort

    又一个比较性质的排序,基本思路是奇数列排一趟序,偶数列排一趟序,再奇数排,再偶数排,直到全部有序 举例吧, 待排数组[6 2 4 1 5 9] 第一次比较奇数列,奇数列与它的邻居偶数列比较,如6和2比 ...

  4. 「6月雅礼集训 2017 Day8」gcd

    [题目大意] 定义times(a, b)表示用辗转相除计算a和b的最大公约数所需步骤. 那么有: 1. times(a, b) = times(b, a) 2. times(a, 0) = 0 3. ...

  5. 基数排序——尚未补完的坑QAQ

    基数排序复杂度是(n+b)logn/logb 我们找一个基数 每次处理一部分位 从低位到高位处理 t是出现次数 s是这个桶管辖的起点 然后就可以写了 不过我这里是指针版的 有点难看 #include& ...

  6. Linux 中使用 dd 测试磁盘性能

    翻译自 : Linux I/O Performance Tests using dd 基本说明 dd 可以用来做简单的低级别复制文件. 这样做, 一般都是可一直直接访问设备文件. 需要说明的是, 错误 ...

  7. 2018 Multi-University Training Contest 1-1002 -Balanced Sequence(括号匹配+贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6299 题目: 题意:t组数据,每组数据给你一个n表示给你n个括号串,这n个括号串之间进行组合,求能够匹 ...

  8. Js如何动态声明变量名

    做个笔记~ var a = 5; for (var i = 1; i <= a; i++) { eval("var a" + i + "=" + i); ...

  9. C++学习之路(六):实现一个String类

    直接贴代码吧,这段时间准备面试也正好练习了一下. class String { public: String(const char *str = ""); ~String(void ...

  10. 给windows设置隐藏文件夹的方法

    cls @ECHO OFF title Folder Private if EXIST "HTG Locker" goto UNLOCK if NOT EXIST Private ...