umychart.index.wechat.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. /*
  2. copyright (c) 2018 jones
  3. http://www.apache.org/licenses/LICENSE-2.0
  4. 开源项目 https://github.com/jones2000/HQChart
  5. jones_2000@163.com
  6. 指标基类及定制指标
  7. */
  8. import {
  9. JSCommonResource_Global_JSChartResource as g_JSChartResource,
  10. } from './umychart.resource.wechat.js'
  11. import { JSCommonComplier } from "./umychart.complier.wechat.js"; //通达信编译器
  12. //图形库
  13. import {
  14. JSCommonChartPaint_IChartPainting as IChartPainting,
  15. JSCommonChartPaint_ChartSingleText as ChartSingleText,
  16. JSCommonChartPaint_ChartKLine as ChartKLine,
  17. JSCommonChartPaint_ChartLine as ChartLine,
  18. JSCommonChartPaint_ChartSubLine as ChartSubLine,
  19. JSCommonChartPaint_ChartPointDot as ChartPointDot,
  20. JSCommonChartPaint_ChartStick as ChartStick,
  21. JSCommonChartPaint_ChartLineStick as ChartLineStick,
  22. JSCommonChartPaint_ChartStickLine as ChartStickLine,
  23. JSCommonChartPaint_ChartOverlayKLine as ChartOverlayKLine,
  24. JSCommonChartPaint_ChartMinuteInfo as ChartMinuteInfo,
  25. JSCommonChartPaint_ChartRectangle as ChartRectangle,
  26. JSCommonChartPaint_ChartMultiText as ChartMultiText,
  27. JSCommonChartPaint_ChartMultiLine as ChartMultiLine,
  28. JSCommonChartPaint_ChartMultiBar as ChartMultiBar,
  29. JSCommonChartPaint_ChartPie as ChartPie,
  30. JSCommonChartPaint_ChartCircle as ChartCircle,
  31. JSCommonChartPaint_ChartChinaMap as ChartChinaMap,
  32. JSCommonChartPaint_ChartRadar as ChartRadar,
  33. JSCommonChartPaint_ChartCorssCursor as ChartCorssCursor,
  34. JSCommonChartPaint_ChartBuySell as ChartBuySell,
  35. JSCommonChartPaint_ChartMACD as ChartMACD,
  36. JSCommonChartPaint_ChartSplashPaint as ChartSplashPaint,
  37. JSCommonChartPaint_ChartBackground as ChartBackground,
  38. JSCommonChartPaint_ChartMinuteVolumBar as ChartMinuteVolumBar,
  39. JSCommonChartPaint_ChartMultiHtmlDom as ChartMultiHtmlDom,
  40. JSCommonChartPaint_ChartLock as ChartLock,
  41. JSCommonChartPaint_ChartVolStick as ChartVolStick,
  42. JSCommonChartPaint_ChartBand as ChartBand,
  43. } from "./umychart.chartpaint.wechat.js";
  44. import
  45. {
  46. JSCommonSplit_CoordinateInfo as CoordinateInfo,
  47. JSCommonSplit_IFrameSplitOperator as IFrameSplitOperator,
  48. JSCommonSplit_FrameSplitKLinePriceY as FrameSplitKLinePriceY,
  49. JSCommonSplit_FrameSplitY as FrameSplitY,
  50. JSCommonSplit_FrameSplitKLineX as FrameSplitKLineX,
  51. JSCommonSplit_FrameSplitMinutePriceY as FrameSplitMinutePriceY,
  52. JSCommonSplit_FrameSplitMinuteX as FrameSplitMinuteX,
  53. JSCommonSplit_FrameSplitXData as FrameSplitXData,
  54. JSCommonSplit_SplitData as SplitData,
  55. JSCommonSplit_PriceSplitData as PriceSplitData,
  56. } from './umychart.framesplit.wechat.js'
  57. import
  58. {
  59. JSCommonChartTitle_IChartTitlePainting as IChartTitlePainting,
  60. JSCommonChartTitle_DynamicKLineTitlePainting as DynamicKLineTitlePainting,
  61. JSCommonChartTitle_DynamicMinuteTitlePainting as DynamicMinuteTitlePainting,
  62. JSCommonChartTitle_DynamicChartTitlePainting as DynamicChartTitlePainting,
  63. JSCommonChartTitle_DynamicTitleData as DynamicTitleData,
  64. JSCommonChartTitle_STRING_FORMAT_TYPE as STRING_FORMAT_TYPE,
  65. } from './umychart.charttitle.wechat.js'
  66. //////////////////////////////////////////////////////////
  67. //
  68. // 指标信息
  69. //
  70. function IndexInfo(name, param)
  71. {
  72. this.Name = name; //名字
  73. this.Param = param; //参数
  74. this.LineColor; //线段颜色
  75. this.ReqeustData = null; //数据请求
  76. }
  77. function BaseIndex(name)
  78. {
  79. this.Index; //指标阐述
  80. this.Name = name; //指标名字
  81. this.UpdateUICallback; //数据到达回调
  82. //默认创建都是线段
  83. this.Create = function (hqChart, windowIndex)
  84. {
  85. for (var i in this.Index)
  86. {
  87. if (!this.Index[i].Name) continue;
  88. var maLine = new ChartLine();
  89. maLine.Canvas = hqChart.Canvas;
  90. maLine.Name = this.Name + '-' + i.toString();
  91. maLine.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  92. maLine.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  93. maLine.Color = this.Index[i].LineColor;
  94. hqChart.ChartPaint.push(maLine);
  95. }
  96. }
  97. //指标不支持 周期/复权/股票等
  98. this.NotSupport = function (hqChart, windowIndex, message)
  99. {
  100. var paint = hqChart.GetChartPaint(windowIndex);
  101. for (var i in paint)
  102. {
  103. paint[i].Data.Data = []; //清空数据
  104. if (i == 0) paint[i].NotSupportMessage = message;
  105. }
  106. }
  107. //格式化指标名字+参数
  108. //格式:指标名(参数1,参数2,参数3,...)
  109. this.FormatIndexTitle = function ()
  110. {
  111. var title = this.Name;
  112. var param = null;
  113. for (var i in this.Index)
  114. {
  115. var item = this.Index[i];
  116. if (item.Param == null) continue;
  117. if (param) param += ',' + item.Param.toString();
  118. else param = item.Param.toString();
  119. }
  120. if (param) title += '(' + param + ')';
  121. return title;
  122. }
  123. this.InvokeUpdateUICallback = function (paint)
  124. {
  125. if (typeof (this.UpdateUICallback) != 'function') return;
  126. let indexData = new Array();
  127. for (let i in paint)
  128. {
  129. indexData.push({ Name: this.Index[i].Name, Data: paint[i].Data });
  130. }
  131. this.UpdateUICallback(indexData);
  132. }
  133. }
  134. //脚本指标
  135. //name=指标名字 args=参数名字 参数值
  136. function ScriptIndex(name, script, args, option)
  137. {
  138. this.newMethod = BaseIndex; //派生
  139. this.newMethod(name);
  140. delete this.newMethod;
  141. this.Script = script;
  142. this.Arguments = [];
  143. this.OutVar = [];
  144. this.ID; //指标ID
  145. this.FloatPrecision = 2; //小数位数
  146. this.StringFormat;
  147. this.KLineType = null; //K线显示类型
  148. this.InstructionType; //五彩K线, 交易指标
  149. this.YSpecificMaxMin = null; //最大最小值
  150. this.YSplitScale = null; //固定刻度
  151. this.OutName=null; //动态输出指标名字
  152. //指标上锁配置信息
  153. this.IsLocked = false; //是否锁住指标
  154. this.LockCallback = null;
  155. this.LockID = null;
  156. this.LockBG = null; //锁背景色
  157. this.LockTextColor = null;
  158. this.LockText = null;
  159. this.LockFont = null;
  160. this.LockCount = 10;
  161. if (option)
  162. {
  163. if (option.FloatPrecision >= 0) this.FloatPrecision = option.FloatPrecision;
  164. if (option.StringFormat > 0) this.StringFormat = option.StringFormat;
  165. if (option.ID) this.ID = option.ID;
  166. if (option.KLineType) this.KLineType = option.KLineType;
  167. if (option.InstructionType) this.InstructionType = option.InstructionType;
  168. if (option.YSpecificMaxMin) this.YSpecificMaxMin = option.YSpecificMaxMin;
  169. if (option.YSplitScale) this.YSplitScale = option.YSplitScale;
  170. if (option.OutName) this.OutName=option.OutName;
  171. }
  172. if (option && option.Lock)
  173. {
  174. if (option.Lock.IsLocked == true) this.IsLocked = true; //指标上锁
  175. if (option.Lock.Callback) this.LockCallback = option.Lock.Callback; //锁回调
  176. if (option.Lock.ID) this.LockID = option.Lock.ID; //锁ID
  177. if (option.Lock.BG) this.LockBG = option.Lock.BG;
  178. if (option.Lock.TextColor) this.LockTextColor = option.Lock.TextColor;
  179. if (option.Lock.Text) this.LockText = option.Lock.Text;
  180. if (option.Lock.Font) this.LockFont = option.Lock.Font;
  181. if (option.Lock.Count) this.LockCount = option.Lock.Count;
  182. }
  183. if (args) this.Arguments = args;
  184. this.SetLock = function (lockData) {
  185. if (lockData.IsLocked == true) {
  186. this.IsLocked = true; //指标上锁
  187. if (lockData.Callback) this.LockCallback = lockData.Callback; //锁回调
  188. if (lockData.ID) this.LockID = lockData.ID; //锁ID
  189. if (lockData.BG) this.LockBG = lockData.BG;
  190. if (lockData.TextColor) this.LockTextColor = lockData.TextColor;
  191. if (lockData.Text) this.LockText = lockData.Text;
  192. if (lockData.Font) this.LockFont = lockData.Font;
  193. if (lockData.Count) this.LockCount = lockData.Count;
  194. }
  195. else { //清空锁配置信息
  196. this.IsLocked = false; //是否锁住指标
  197. this.LockCallback = null;
  198. this.LockID = null;
  199. this.LockBG = null; //锁背景色
  200. this.LockTextColor = null;
  201. this.LockText = null;
  202. this.LockFont = null;
  203. this.LockCount = 10;
  204. }
  205. }
  206. this.ExecuteScript = function (hqChart, windowIndex, hisData)
  207. {
  208. this.OutVar = [];
  209. let self = this;
  210. let param =
  211. {
  212. HQChart: hqChart,
  213. WindowIndex: windowIndex,
  214. HistoryData: hisData,
  215. Self: this
  216. };
  217. let hqDataType = 0; //默认K线
  218. if (hqChart.ClassName === 'MinuteChartContainer') hqDataType = 2; //分钟数据
  219. let option =
  220. {
  221. HQDataType: hqDataType,
  222. Symbol: hqChart.Symbol,
  223. Data: hisData,
  224. SourceData: hqChart.SourceData, //原始数据
  225. Callback: this.RecvResultData, CallbackParam: param,
  226. Async: true,
  227. MaxReqeustDataCount: hqChart.MaxReqeustDataCount,
  228. MaxRequestMinuteDayCount: hqChart.MaxRequestMinuteDayCount,
  229. Arguments: this.Arguments
  230. };
  231. if (hqChart.NetworkFilter) option.NetworkFilter = hqChart.NetworkFilter;
  232. let code = this.Script;
  233. let run = JSCommonComplier.JSComplier.Execute(code, option, hqChart.ScriptErrorCallback);
  234. }
  235. this.RecvResultData = function (outVar, param)
  236. {
  237. let hqChart = param.HQChart;
  238. let windowIndex = param.WindowIndex;
  239. let hisData = param.HistoryData;
  240. param.Self.OutVar = outVar;
  241. param.Self.BindData(hqChart, windowIndex, hisData);
  242. if (param.Self.IsLocked == false) //不上锁
  243. {
  244. param.HQChart.Frame.SubFrame[windowIndex].Frame.SetLock(null);
  245. }
  246. else //上锁
  247. {
  248. let lockData =
  249. {
  250. IsLocked: true, Callback: param.Self.LockCallback, IndexName: param.Self.Name, ID: param.Self.LockID,
  251. BG: param.Self.LockBG, Text: param.Self.LockText, TextColor: param.Self.LockTextColor, Font: param.Self.LockFont,
  252. Count: param.Self.LockCount
  253. };
  254. param.HQChart.Frame.SubFrame[windowIndex].Frame.SetLock(lockData);
  255. }
  256. param.HQChart.UpdataDataoffset(); //更新数据偏移
  257. param.HQChart.UpdateFrameMaxMin(); //调整坐标最大 最小值
  258. param.HQChart.Draw();
  259. var event = hqChart.GetIndexEvent(); //指标计算完成回调
  260. if (event)
  261. {
  262. var self = param.Self;
  263. var data = {
  264. OutVar: self.OutVar, WindowIndex: windowIndex, Name: self.Name, Arguments: self.Arguments, HistoryData: hisData,
  265. Stock: { Symbol: hqChart.Symbol, Name: hqChart.Name }
  266. };
  267. event.Callback(event, data, self);
  268. }
  269. }
  270. this.CreateLine = function (hqChart, windowIndex, varItem, id)
  271. {
  272. let line = new ChartLine();
  273. line.Canvas = hqChart.Canvas;
  274. line.DrawType = 1; //无效数不画
  275. line.Name = varItem.Name;
  276. line.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  277. line.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  278. if (varItem.Color) line.Color = this.GetColor(varItem.Color);
  279. else line.Color = this.GetDefaultColor(id);
  280. if (varItem.IsShow==false) line.IsShow=false;
  281. if (varItem.LineWidth)
  282. {
  283. let width = parseInt(varItem.LineWidth.replace("LINETHICK", ""));
  284. if (!isNaN(width) && width > 0) line.LineWidth = width;
  285. }
  286. if (varItem.IsDotLine) line.IsDotLine = true; //虚线
  287. if (varItem.IsShow == false) line.IsShow = false;
  288. let titleIndex = windowIndex + 1;
  289. line.Data.Data = varItem.Data;
  290. if (varItem.IsShowTitle===false) //NOTEXT 不绘制标题
  291. {
  292. }
  293. else if (IFrameSplitOperator.IsString(varItem.Name) && varItem.Name.indexOf("NOTEXT")==0) //标题中包含NOTEXT不绘制标题
  294. {
  295. }
  296. else
  297. {
  298. hqChart.TitlePaint[titleIndex].Data[id] = new DynamicTitleData(line.Data, (varItem.NoneName==true? null: varItem.Name) , line.Color);
  299. }
  300. hqChart.ChartPaint.push(line);
  301. }
  302. this.CreateOverlayLine = function (hqChart, windowIndex, varItem, id)
  303. {
  304. let line = new ChartSubLine();
  305. line.Canvas = hqChart.Canvas;
  306. line.DrawType = 1; //无效数不画
  307. line.Name = varItem.Name;
  308. line.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  309. line.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  310. if (varItem.Color) line.Color = this.GetColor(varItem.Color);
  311. else line.Color = this.GetDefaultColor(id);
  312. if (varItem.LineWidth) {
  313. let width = parseInt(varItem.LineWidth.replace("LINETHICK", ""));
  314. if (!isNaN(width) && width > 0) line.LineWidth = width;
  315. }
  316. if (varItem.IsDotLine) line.IsDotLine = true; //虚线
  317. if (varItem.IsShow == false) line.IsShow = false;
  318. let titleIndex = windowIndex + 1;
  319. line.Data.Data = varItem.Data;
  320. hqChart.TitlePaint[titleIndex].Data[id] = new DynamicTitleData(line.Data, varItem.Name, line.Color);
  321. hqChart.ChartPaint.push(line);
  322. }
  323. //创建柱子
  324. this.CreateBar = function (hqChart, windowIndex, varItem, id)
  325. {
  326. let bar = new ChartStickLine();
  327. bar.Canvas = hqChart.Canvas;
  328. if (varItem.Draw.Width > 0) bar.LineWidth = varItem.Draw.Width;
  329. else bar.LineWidth=1;
  330. bar.Name = varItem.Name;
  331. bar.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  332. bar.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  333. if (varItem.Color) bar.Color = this.GetColor(varItem.Color);
  334. else bar.Color = this.GetDefaultColor(id);
  335. let titleIndex = windowIndex + 1;
  336. bar.Data.Data = varItem.Draw.DrawData;
  337. bar.BarType = varItem.Draw.Type;
  338. //hqChart.TitlePaint[titleIndex].Data[id]=new DynamicTitleData(bar.Data,varItem.Name,bar.Color);
  339. hqChart.ChartPaint.push(bar);
  340. }
  341. //创建文本
  342. this.CreateText = function (hqChart, windowIndex, varItem, id)
  343. {
  344. let chartText = new ChartSingleText();
  345. chartText.Canvas = hqChart.Canvas;
  346. chartText.TextAlign='left';
  347. chartText.Name = varItem.Name;
  348. chartText.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  349. chartText.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  350. chartText.ReloadResource();
  351. if (varItem.Color) chartText.Color = this.GetColor(varItem.Color);
  352. else chartText.Color = this.GetDefaultColor(id);
  353. let titleIndex = windowIndex + 1;
  354. if (varItem.Draw.Position) chartText.Position=varItem.Draw.Position; //赋值坐标
  355. if (varItem.Draw.DrawData) chartText.Data.Data = varItem.Draw.DrawData;
  356. chartText.Text = varItem.Draw.Text;
  357. if (varItem.Draw.Direction > 0) chartText.Direction = varItem.Draw.Direction;
  358. if (varItem.Draw.YOffset > 0) chartText.YOffset = varItem.Draw.YOffset;
  359. if (varItem.Draw.TextAlign) chartText.TextAlign = varItem.Draw.TextAlign;
  360. //hqChart.TitlePaint[titleIndex].Data[id]=new DynamicTitleData(bar.Data,varItem.Name,bar.Color);
  361. hqChart.ChartPaint.push(chartText);
  362. }
  363. //COLORSTICK
  364. this.CreateMACD = function (hqChart, windowIndex, varItem, id)
  365. {
  366. let chartMACD = new ChartMACD();
  367. chartMACD.Canvas = hqChart.Canvas;
  368. chartMACD.Name = varItem.Name;
  369. chartMACD.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  370. chartMACD.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  371. if (varItem.LineWidth)
  372. {
  373. var width=parseInt(varItem.LineWidth.replace("LINETHICK",""));
  374. if (!isNaN(width) && width>0) chartMACD.LineWidth=width;
  375. }
  376. let titleIndex = windowIndex + 1;
  377. chartMACD.Data.Data = varItem.Data;
  378. var clrTitle=this.GetDefaultColor(id);
  379. if (varItem.Color) clrTitle= this.GetColor(varItem.Color);
  380. hqChart.TitlePaint[titleIndex].Data[id] = new DynamicTitleData(chartMACD.Data, varItem.Name, clrTitle);
  381. hqChart.ChartPaint.push(chartMACD);
  382. }
  383. this.CreatePointDot = function (hqChart, windowIndex, varItem, id) {
  384. let pointDot = new ChartPointDot();
  385. pointDot.Canvas = hqChart.Canvas;
  386. pointDot.Name = varItem.Name;
  387. pointDot.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  388. pointDot.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  389. if (varItem.Color) pointDot.Color = this.GetColor(varItem.Color);
  390. else pointDot.Color = this.GetDefaultColor(id);
  391. if (varItem.Radius) pointDot.Radius = varItem.Radius;
  392. if (varItem.LineWidth) {
  393. let width = parseInt(varItem.LineWidth.replace("LINETHICK", ""));
  394. if (!isNaN(width) && width > 0) pointDot.Radius = width;
  395. }
  396. let titleIndex = windowIndex + 1;
  397. pointDot.Data.Data = varItem.Data;
  398. hqChart.TitlePaint[titleIndex].Data[id] = new DynamicTitleData(pointDot.Data, varItem.Name, pointDot.Color);
  399. hqChart.ChartPaint.push(pointDot);
  400. }
  401. this.CreateStick = function (hqChart, windowIndex, varItem, id) {
  402. let chart = new ChartStick();
  403. chart.Canvas = hqChart.Canvas;
  404. chart.Name = varItem.Name;
  405. chart.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  406. chart.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  407. if (varItem.Color) chart.Color = this.GetColor(varItem.Color);
  408. else chart.Color = this.GetDefaultColor(id);
  409. if (varItem.LineWidth) {
  410. let width = parseInt(varItem.LineWidth.replace("LINETHICK", ""));
  411. if (!isNaN(width) && width > 0) chart.LineWidth = width;
  412. }
  413. let titleIndex = windowIndex + 1;
  414. chart.Data.Data = varItem.Data;
  415. hqChart.TitlePaint[titleIndex].Data[id] = new DynamicTitleData(chart.Data, varItem.Name, chart.Color);
  416. hqChart.ChartPaint.push(chart);
  417. }
  418. this.CreateLineStick = function (hqChart, windowIndex, varItem, id) {
  419. let chart = new ChartLineStick();
  420. chart.Canvas = hqChart.Canvas;
  421. chart.Name = varItem.Name;
  422. chart.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  423. chart.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  424. if (varItem.Color) chart.Color = this.GetColor(varItem.Color);
  425. else chart.Color = this.GetDefaultColor(id);
  426. if (varItem.LineWidth) {
  427. let width = parseInt(varItem.LineWidth.replace("LINETHICK", ""));
  428. if (!isNaN(width) && width > 0) chart.LineWidth = width;
  429. }
  430. let titleIndex = windowIndex + 1;
  431. chart.Data.Data = varItem.Data;
  432. hqChart.TitlePaint[titleIndex].Data[id] = new DynamicTitleData(chart.Data, varItem.Name, chart.Color);
  433. hqChart.ChartPaint.push(chart);
  434. }
  435. this.CreateStraightLine = function (hqChart, windowIndex, varItem, id) {
  436. let line = new ChartLine();
  437. line.DrawType = 1;
  438. line.Canvas = hqChart.Canvas;
  439. line.Name = varItem.Name;
  440. line.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  441. line.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  442. if (varItem.Color) line.Color = this.GetColor(varItem.Color);
  443. else line.Color = this.GetDefaultColor(id);
  444. if (varItem.LineWidth) {
  445. let width = parseInt(varItem.LineWidth.replace("LINETHICK", ""));
  446. if (!isNaN(width) && width > 0) line.LineWidth = width;
  447. }
  448. let titleIndex = windowIndex + 1;
  449. line.Data.Data = varItem.Draw.DrawData;
  450. //hqChart.TitlePaint[titleIndex].Data[id]=new DynamicTitleData(line.Data,varItem.Name,line.Color);
  451. hqChart.ChartPaint.push(line);
  452. }
  453. this.CreateVolStick = function (hqChart, windowIndex, varItem, id, hisData) {
  454. let chart = new ChartVolStick();
  455. chart.Canvas = hqChart.Canvas;
  456. chart.Name = varItem.Name;
  457. chart.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  458. chart.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  459. chart.KLineDrawType = hqChart.KLineDrawType; //设置K线显示类型
  460. if (varItem.Color) chart.Color = this.GetColor(varItem.Color);
  461. else chart.Color = this.GetDefaultColor(id);
  462. let titleIndex = windowIndex + 1;
  463. chart.Data.Data = varItem.Data;
  464. chart.HistoryData = hisData;
  465. hqChart.TitlePaint[titleIndex].Data[id] = new DynamicTitleData(chart.Data, varItem.Name, chart.Color);
  466. hqChart.ChartPaint.push(chart);
  467. }
  468. this.CreateBand = function (hqChart, windowIndex, varItem, id) {
  469. let chart = new ChartBand();
  470. chart.Canvas = hqChart.Canvas;
  471. chart.Name = varItem.Name;
  472. chart.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  473. chart.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  474. chart.FirstColor = varItem.Draw.Color[0];
  475. chart.SecondColor = varItem.Draw.Color[1];
  476. chart.Data.Data = varItem.Draw.DrawData;
  477. hqChart.ChartPaint.push(chart);
  478. }
  479. this.CreatePolyLine = function (hqChart, windowIndex, varItem, id) {
  480. let line = new ChartLine();
  481. line.Canvas = hqChart.Canvas;
  482. line.Name = varItem.Name;
  483. line.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  484. line.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  485. if (varItem.Color) line.Color = this.GetColor(varItem.Color);
  486. else line.Color = this.GetDefaultColor(id);
  487. if (varItem.LineWidth) {
  488. let width = parseInt(varItem.LineWidth.replace("LINETHICK", ""));
  489. if (!isNaN(width) && width > 0) line.LineWidth = width;
  490. }
  491. let titleIndex = windowIndex + 1;
  492. line.Data.Data = varItem.Draw.DrawData;
  493. //hqChart.TitlePaint[titleIndex].Data[id] = new DynamicTitleData(line.Data, ' ', line.Color); //给一个空的标题
  494. hqChart.ChartPaint.push(line);
  495. }
  496. //创建K线图
  497. this.CreateKLine = function (hqChart, windowIndex, varItem, id) {
  498. let chart = new ChartKLine();
  499. chart.Canvas = hqChart.Canvas;
  500. chart.Name = varItem.Name;
  501. chart.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  502. chart.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  503. chart.Data.Data = varItem.Draw.DrawData;
  504. chart.IsShowMaxMinPrice = false;
  505. if (varItem.Color) //如果设置了颜色,使用外面设置的颜色
  506. chart.UnchagneColor = chart.DownColor = chart.UpColor = this.GetColor(varItem.Color);
  507. hqChart.ChartPaint.push(chart);
  508. }
  509. this.CreateNumberText = function (hqChart, windowIndex, varItem, id) {
  510. let chartText = new ChartSingleText();
  511. chartText.Canvas = hqChart.Canvas;
  512. chartText.Name = varItem.Name;
  513. chartText.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  514. chartText.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  515. chartText.ReloadResource();
  516. chartText.TextAlign="center";
  517. if (varItem.Color) chartText.Color = this.GetColor(varItem.Color);
  518. else chartText.Color = this.GetDefaultColor(id);
  519. if (varItem.IsDrawAbove) chartText.Direction=1;
  520. else chartText.Direction=2;
  521. let titleIndex = windowIndex + 1;
  522. chartText.Data.Data = varItem.Draw.DrawData.Value;
  523. chartText.Text = varItem.Draw.DrawData.Text;
  524. //hqChart.TitlePaint[titleIndex].Data[id]=new DynamicTitleData(bar.Data,varItem.Name,bar.Color);
  525. hqChart.ChartPaint.push(chartText);
  526. }
  527. //创建图标
  528. this.CreateIcon = function (hqChart, windowIndex, varItem, id) {
  529. let chartText = new ChartSingleText();
  530. chartText.Canvas = hqChart.Canvas;
  531. chartText.TextAlign = 'center';
  532. chartText.Name = varItem.Name;
  533. chartText.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  534. chartText.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  535. let titleIndex = windowIndex + 1;
  536. chartText.Data.Data = varItem.Draw.DrawData;
  537. chartText.Text = varItem.Draw.Icon.Symbol;
  538. if (varItem.Color) chartText.Color = this.GetColor(varItem.Color);
  539. else if (varItem.Draw.Icon.Color) chartText.Color = varItem.Draw.Icon.Color;
  540. else chartText.Color = 'rgb(0,0,0)';
  541. //hqChart.TitlePaint[titleIndex].Data[id]=new DynamicTitleData(bar.Data,varItem.Name,bar.Color);
  542. hqChart.ChartPaint.push(chartText);
  543. }
  544. this.CreateRectangle = function (hqChart, windowIndex, varItem, i)
  545. {
  546. let chart = new ChartRectangle();
  547. chart.Canvas = hqChart.Canvas;
  548. chart.Name = varItem.Name;
  549. chart.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  550. chart.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  551. chart.Color = [varItem.Draw.DrawData.Color];
  552. chart.Rect = varItem.Draw.DrawData.Rect;
  553. if (varItem.Color) chart.BorderColor = this.GetColor(varItem.Color);
  554. hqChart.ChartPaint.push(chart);
  555. }
  556. this.CreateBackgroud=function(hqChart,windowIndex,varItem,id)
  557. {
  558. let chart=new ChartBackground();
  559. chart.Canvas=hqChart.Canvas;
  560. chart.Name=varItem.Name;
  561. chart.ChartBorder=hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  562. chart.ChartFrame=hqChart.Frame.SubFrame[windowIndex].Frame;
  563. if (varItem.Draw && varItem.Draw.DrawData)
  564. {
  565. var drawData=varItem.Draw.DrawData;
  566. chart.Color=drawData.Color;
  567. chart.ColorAngle=drawData.Angle;
  568. if (drawData.Data) chart.Data.Data=drawData.Data;
  569. }
  570. hqChart.ChartPaint.push(chart);
  571. }
  572. this.CreateMultiText = function (hqChart, windowIndex, varItem, i)
  573. {
  574. let chart = new ChartMultiText();
  575. chart.Canvas = hqChart.Canvas;
  576. chart.Name = varItem.Name;
  577. chart.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  578. chart.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  579. chart.Data = hqChart.ChartPaint[0].Data;//绑定K线
  580. chart.Texts = varItem.Draw.DrawData;
  581. hqChart.ChartPaint.push(chart);
  582. }
  583. this.CreateMulitHtmlDom=function(hqChart,windowIndex,varItem,i)
  584. {
  585. let chart=new ChartMultiHtmlDom();
  586. chart.Canvas=hqChart.Canvas;
  587. chart.Name=varItem.Name;
  588. chart.ChartBorder=hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  589. chart.ChartFrame=hqChart.Frame.SubFrame[windowIndex].Frame;
  590. chart.Data=hqChart.ChartPaint[0].Data;//绑定K线
  591. chart.Texts=varItem.Draw.DrawData;
  592. chart.DrawCallback= varItem.Draw.Callback;
  593. hqChart.ChartPaint.push(chart);
  594. }
  595. this.CreateMultiLine = function (hqChart, windowIndex, varItem, i)
  596. {
  597. let chart = new ChartMultiLine();
  598. chart.Canvas = hqChart.Canvas;
  599. chart.Name = varItem.Name;
  600. chart.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  601. chart.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  602. chart.Data = hqChart.ChartPaint[0].Data;//绑定K线
  603. chart.Lines = varItem.Draw.DrawData;
  604. if (varItem.Draw.LineDash) chart.LineDash=varItem.Draw.LineDash;
  605. if (IFrameSplitOperator.IsNumber(varItem.Draw.LineWidth)) chart.LineWidth=varItem.Draw.LineWidth;
  606. hqChart.ChartPaint.push(chart);
  607. }
  608. this.CreateMultiBar = function (hqChart, windowIndex, varItem, i)
  609. {
  610. let chart = new ChartMultiBar();
  611. chart.Canvas = hqChart.Canvas;
  612. chart.Name = varItem.Name;
  613. chart.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  614. chart.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  615. chart.Data = hqChart.ChartPaint[0].Data;//绑定K线
  616. chart.Bars = varItem.Draw.DrawData;
  617. hqChart.ChartPaint.push(chart);
  618. }
  619. //创建K线背景
  620. this.CreateSelfKLine = function (hqChart, windowIndex, hisData)
  621. {
  622. let chart = new ChartKLine();
  623. chart.Canvas = hqChart.Canvas;
  624. chart.Name = "Self Kline"
  625. chart.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  626. chart.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  627. chart.Data = hisData
  628. chart.IsShowMaxMinPrice = false;
  629. chart.IsShowKTooltip = false;
  630. chart.DrawType = this.KLineType;
  631. hqChart.ChartPaint.push(chart);
  632. }
  633. this.BindInstructionData = function (hqChart, windowIndex, hisData) //绑定指示指标
  634. {
  635. if (this.OutVar == null || this.OutVar.length < 0) return;
  636. if (this.InstructionType == 2)
  637. {
  638. let varItem = this.OutVar[this.OutVar.length - 1]; //取最后一组数据作为指示数据
  639. hqChart.SetInstructionData(this.InstructionType, { Data: varItem.Data }); //设置指示数据
  640. return true;
  641. }
  642. else if (this.InstructionType == 1) //交易系统
  643. {
  644. var buyData, sellData;
  645. for (var i in this.OutVar)
  646. {
  647. let item = this.OutVar[i];
  648. if (item.Name == 'ENTERLONG') buyData = item.Data;
  649. else if (item.Name == 'EXITLONG') sellData = item.Data;
  650. }
  651. hqChart.SetInstructionData(this.InstructionType, { Buy: buyData, Sell: sellData }); //设置指示数据
  652. return true;
  653. }
  654. }
  655. this.BindData = function (hqChart, windowIndex, hisData)
  656. {
  657. if (windowIndex == 0 && this.InstructionType)
  658. {
  659. this.BindInstructionData(hqChart, windowIndex, hisData);
  660. return;
  661. }
  662. //清空指标图形
  663. hqChart.DeleteIndexPaint(windowIndex);
  664. if (windowIndex == 0) hqChart.ShowKLine(true);
  665. if (this.OutVar == null || this.OutVar.length < 0) return;
  666. //叠加一个K线背景
  667. if (this.KLineType != null)
  668. {
  669. if (this.KLineType === 0 || this.KLineType === 1 || this.KLineType === 2) this.CreateSelfKLine(hqChart, windowIndex, hisData);
  670. else if (this.KLineType === -1 && windowIndex == 0) hqChart.ShowKLine(false);
  671. }
  672. if (windowIndex >= 1 && hqChart.Frame)
  673. {
  674. hqChart.Frame.SubFrame[windowIndex].Frame.YSplitOperator.FloatPrecision = this.FloatPrecision;
  675. if (this.YSpecificMaxMin) hqChart.Frame.SubFrame[windowIndex].Frame.YSpecificMaxMin = this.YSpecificMaxMin; //最大最小值
  676. if (this.YSplitScale) hqChart.Frame.SubFrame[windowIndex].Frame.YSplitScale = this.YSplitScale; //固定刻度
  677. }
  678. for (let i in this.OutVar)
  679. {
  680. let item = this.OutVar[i];
  681. if (item.IsExData === true) continue; //扩展数据不显示图形
  682. if (item.Type==1000 || item.Type==1001) continue; //数据集合, 字符串
  683. if (item.Type == 0)
  684. {
  685. if (item.IsOverlayLine) this.CreateOverlayLine(hqChart, windowIndex, item, i);
  686. else this.CreateLine(hqChart, windowIndex, item, i);
  687. }
  688. else if (item.Type == 1)
  689. {
  690. switch (item.Draw.DrawType)
  691. {
  692. case 'STICKLINE':
  693. this.CreateBar(hqChart, windowIndex, item, i);
  694. break;
  695. case 'DRAWTEXT':
  696. case 'SUPERDRAWTEXT':
  697. case 'DRAWTEXT_FIX':
  698. this.CreateText(hqChart, windowIndex, item, i);
  699. break;
  700. case 'DRAWLINE':
  701. this.CreateStraightLine(hqChart, windowIndex, item, i);
  702. break;
  703. case 'DRAWBAND':
  704. this.CreateBand(hqChart, windowIndex, item, i);
  705. break;
  706. case 'DRAWKLINE':
  707. this.CreateKLine(hqChart, windowIndex, item, i);
  708. break;
  709. case 'DRAWKLINE_IF':
  710. this.CreateKLine(hqChart, windowIndex, item, i);
  711. break;
  712. case 'POLYLINE':
  713. this.CreatePolyLine(hqChart, windowIndex, item, i);
  714. break;
  715. case 'DRAWNUMBER':
  716. this.CreateNumberText(hqChart, windowIndex, item, i);
  717. break;
  718. case 'DRAWICON':
  719. this.CreateIcon(hqChart, windowIndex, item, i);
  720. break;
  721. case 'DRAWRECTREL':
  722. this.CreateRectangle(hqChart, windowIndex, item, i);
  723. break;
  724. case 'DRAWGBK':
  725. case "DRAWGBK2":
  726. this.CreateBackgroud(hqChart,windowIndex,item,i);
  727. break;
  728. //第3方指标定制
  729. case 'MULTI_TEXT':
  730. this.CreateMultiText(hqChart, windowIndex, item, i);
  731. break;
  732. case "MULTI_HTMLDOM":
  733. this.CreateMulitHtmlDom(hqChart,windowIndex,item,i);
  734. break;
  735. case 'MULTI_LINE':
  736. this.CreateMultiLine(hqChart, windowIndex, item, i);
  737. break;
  738. case 'MULTI_BAR':
  739. this.CreateMultiBar(hqChart, windowIndex, item, i);
  740. break;
  741. case "KLINE_BG":
  742. this.CreateBackgroud(hqChart,windowIndex,item,i);
  743. break;
  744. }
  745. }
  746. else if (item.Type == 2)
  747. {
  748. this.CreateMACD(hqChart, windowIndex, item, i);
  749. }
  750. else if (item.Type == 3)
  751. {
  752. this.CreatePointDot(hqChart, windowIndex, item, i);
  753. }
  754. else if (item.Type == 4)
  755. {
  756. this.CreateLineStick(hqChart, windowIndex, item, i);
  757. }
  758. else if (item.Type == 5)
  759. {
  760. this.CreateStick(hqChart, windowIndex, item, i);
  761. }
  762. else if (item.Type == 6)
  763. {
  764. this.CreateVolStick(hqChart, windowIndex, item, i, hisData);
  765. }
  766. var titlePaint = hqChart.TitlePaint[windowIndex + 1];
  767. if (titlePaint && titlePaint.Data && i < titlePaint.Data.length) //设置标题数值 小数位数和格式
  768. {
  769. if (this.StringFormat > 0) titlePaint.Data[i].StringFormat = this.StringFormat;
  770. if (this.FloatPrecision >= 0) titlePaint.Data[i].FloatPrecision = this.FloatPrecision;
  771. if (this.OutName && this.OutName.length>0 && this.Arguments && this.Arguments.length>0)
  772. {
  773. titlePaint.SetDynamicOutName(this.OutName,this.Arguments);
  774. }
  775. }
  776. }
  777. let titleIndex = windowIndex + 1;
  778. hqChart.TitlePaint[titleIndex].Title = this.Name;
  779. let indexParam = '';
  780. for (let i in this.Arguments)
  781. {
  782. let item = this.Arguments[i];
  783. if (indexParam.length > 0) indexParam += ',';
  784. indexParam += item.Value.toString();
  785. }
  786. if (indexParam.length > 0) hqChart.TitlePaint[titleIndex].Title = this.Name + '(' + indexParam + ')';
  787. if (hqChart.UpdateUICallback) hqChart.UpdateUICallback('ScriptIndex', this.OutVar,
  788. { WindowIndex: windowIndex, Name: this.Name, Arguments: this.Arguments, HistoryData: hisData }); //通知上层回调
  789. return true;
  790. }
  791. this.GetDefaultColor = function (id) //给一个默认的颜色
  792. {
  793. let COLOR_ARRAY = g_JSChartResource.ColorArray;
  794. let number = parseInt(id);
  795. return COLOR_ARRAY[number % (COLOR_ARRAY.length - 1)];
  796. }
  797. this.GetColor = function (colorName) //获取颜色
  798. {
  799. let COLOR_MAP = new Map([
  800. ['COLORBLACK', 'rgb(0,0,0)'],
  801. ['COLORBLUE', 'rgb(18,95,216)'],
  802. ['COLORGREEN', 'rgb(25,158,0)'],
  803. ['COLORCYAN', 'rgb(0,255,198)'],
  804. ['COLORRED', 'rgb(238,21,21)'],
  805. ['COLORMAGENTA', 'rgb(255,0,222)'],
  806. ['COLORBROWN', 'rgb(149,94,15)'],
  807. ['COLORLIGRAY', 'rgb(218,218,218)'], //画淡灰色
  808. ['COLORGRAY', 'rgb(133,133,133)'], //画深灰色
  809. ['COLORLIBLUE', 'rgb(94,204,255)'], //淡蓝色
  810. ['COLORLIGREEN', 'rgb(183,255,190)'], //淡绿色
  811. ['COLORLICYAN', 'rgb(154,255,242)'], //淡青色
  812. ['COLORLIRED', 'rgb(255,172,172)'], //淡红色
  813. ['COLORLIMAGENTA', 'rgb(255,145,241)'], //淡洋红色
  814. ['COLORWHITE', 'rgb(255,255,255)'], //白色
  815. ['COLORYELLOW', 'rgb(255,198,0)']
  816. ]);
  817. if (COLOR_MAP.has(colorName)) return COLOR_MAP.get(colorName);
  818. //COLOR 自定义色
  819. //格式为COLOR+“RRGGBB”:RR、GG、BB表示红色、绿色和蓝色的分量,每种颜色的取值范围是00-FF,采用了16进制。
  820. //例如:MA5:MA(CLOSE,5),COLOR00FFFF 表示纯红色与纯绿色的混合色:COLOR808000表示淡蓝色和淡绿色的混合色。
  821. if (colorName.indexOf('COLOR') == 0) return '#' + colorName.substr(5);
  822. return 'rgb(30,144,255)';
  823. }
  824. }
  825. //市场多空
  826. function MarketLongShortIndex()
  827. {
  828. this.newMethod = BaseIndex; //派生
  829. this.newMethod('市场多空');
  830. delete this.newMethod;
  831. this.Index = new Array(
  832. new IndexInfo("多空指标", null),
  833. new IndexInfo("多头区域", null),
  834. new IndexInfo("空头区域", null)
  835. );
  836. this.Index[0].LineColor = g_JSChartResource.Index.LineColor[0];
  837. this.Index[1].LineColor = g_JSChartResource.UpBarColor;
  838. this.Index[2].LineColor = g_JSChartResource.DownBarColor;
  839. this.LongShortData; //多空数据
  840. this.Create = function (hqChart, windowIndex) {
  841. for (var i in this.Index) {
  842. var paint = null;
  843. if (i == 0)
  844. paint = new ChartLine();
  845. else
  846. paint = new ChartStraightLine();
  847. paint.Color = this.Index[i].LineColor;
  848. paint.Canvas = hqChart.Canvas;
  849. paint.Name = this.Name + "-" + i.toString();
  850. paint.ChartBorder = hqChart.Frame.SubFrame[windowIndex].Frame.ChartBorder;
  851. paint.ChartFrame = hqChart.Frame.SubFrame[windowIndex].Frame;
  852. hqChart.ChartPaint.push(paint);
  853. }
  854. }
  855. //请求数据
  856. this.RequestData = function (hqChart, windowIndex, hisData) {
  857. var self = this;
  858. var param =
  859. {
  860. HQChart: hqChart,
  861. WindowIndex: windowIndex,
  862. HistoryData: hisData
  863. };
  864. this.LongShortData = [];
  865. if (param.HQChart.Period > 0) //周期数据
  866. {
  867. this.NotSupport(param.HQChart, param.WindowIndex, "不支持周期切换");
  868. param.HQChart.Draw();
  869. return false;
  870. }
  871. //请求数据
  872. wx.request({
  873. url: g_JSChartResource.Index.MarketLongShortApiUrl,
  874. data:
  875. {
  876. },
  877. method: 'POST',
  878. dataType: "json",
  879. async: true,
  880. success: function (recvData) {
  881. self.RecvData(recvData, param);
  882. }
  883. });
  884. return true;
  885. }
  886. this.RecvData = function (recvData, param) {
  887. if (recvData.data.data.length <= 0) return;
  888. var aryData = new Array();
  889. for (var i in recvData.data.data) {
  890. var item = recvData.data.data[i];
  891. var indexData = new SingleData();
  892. indexData.Date = item[0];
  893. indexData.Value = item[1];
  894. aryData.push(indexData);
  895. }
  896. var aryFittingData = param.HistoryData.GetFittingData(aryData);
  897. var bindData = new ChartData();
  898. bindData.Data = aryFittingData;
  899. bindData.Period = param.HQChart.Period; //周期
  900. bindData.Right = param.HQChart.Right; //复权
  901. this.LongShortData = bindData.GetValue();
  902. this.BindData(param.HQChart, param.WindowIndex, param.HistoryData);
  903. param.HQChart.UpdataDataoffset(); //更新数据偏移
  904. param.HQChart.UpdateFrameMaxMin(); //调整坐标最大 最小值
  905. param.HQChart.Draw();
  906. }
  907. this.BindData = function (hqChart, windowIndex, hisData) {
  908. var paint = hqChart.GetChartPaint(windowIndex);
  909. if (paint.length != this.Index.length) return false;
  910. //paint[0].Data.Data=SWLData;
  911. paint[0].Data.Data = this.LongShortData;
  912. paint[0].NotSupportMessage = null;
  913. paint[1].Data.Data[0] = 8;
  914. paint[2].Data.Data[0] = 1;
  915. //指定[0,9]
  916. hqChart.Frame.SubFrame[windowIndex].Frame.YSpecificMaxMin = { Max: 9, Min: 0, Count: 3 };
  917. var titleIndex = windowIndex + 1;
  918. for (var i in paint) {
  919. hqChart.TitlePaint[titleIndex].Data[i] = new DynamicTitleData(paint[i].Data, this.Index[i].Name, this.Index[i].LineColor);
  920. if (i > 0) hqChart.TitlePaint[titleIndex].Data[i].DataType = "StraightLine";
  921. }
  922. hqChart.TitlePaint[titleIndex].Title = this.FormatIndexTitle();
  923. if (hqChart.UpdateUICallback) hqChart.UpdateUICallback('MarketLongShortIndex', paint, { WindowIndex: windowIndex, HistoryData: hisData }); //通知上层回调
  924. return true;
  925. }
  926. }
  927. module.exports =
  928. {
  929. JSCommonIndex:
  930. {
  931. IndexInfo: IndexInfo,
  932. BaseIndex: BaseIndex,
  933. ScriptIndex:ScriptIndex,
  934. },
  935. //单个类导出
  936. JSCommonIndex_IndexInfo: IndexInfo,
  937. JSCommonIndex_BaseIndex: BaseIndex,
  938. JSCommonIndex_ScriptIndex:ScriptIndex,
  939. };