HQChart使用教程13-5分钟完成一个小程序K线图

151 篇文章 33 订阅

HQChart使用教程13-5分钟完成一个小程序K线图

效果图

在这里插入图片描述
在这里插入图片描述

下载HQChart组件

https://github.com/jones2000/HQChart
把 \trunk\wechathqchart 目录拷贝到小程序项目的目录里面。

配置 WXML

新建一个小程序页面,
在WXML里面增加一个’canvas’元素, 并设置canvas-id, 定义好手势事件,bindtouchstartbindtouchmovebindtouchend

<view class="container">
  <canvas class="historychart"  canvas-id="historychart" 
    style="height:{{Height}}px; width:{{Width}}px;" 
    bindtouchstart='historytouchstart' bindtouchmove='historytouchmove' bindtouchend='historytouchend'/>

</view>

配置页面js文件

在对应的页面js文件里面 import HQChart组件 (wechathqchart/umychart.wechat.3.0.js)

import { JSCommon } from "../wechathqchart/umychart.wechat.3.0.js";   

Page(
  {
    data:
    {
      Height: 0,
      Width: 0,
       },

    HistoryChart: null,

    HistoryOption:
    {
        Type: '历史K线图',
        Windows: //窗口指标
        [
            { Index: 'MA' },
            { Index: 'VOL'},
            { Index: 'RSI' }
                    ],
        //ColorIndex: { Index: '五彩K线-双飞乌鸦' },   //五彩K线
        //TradeIndex: { Index: '交易系统-BIAS' },    //交易系统
        Symbol: "000001.sz",
        IsAutoUpate: true,       //是自动更新数据

        IsShowCorssCursorInfo: true,    //是否显示十字光标的刻度信息
        CorssCursorTouchEnd:true,       //手离开屏幕 隐藏十字光标
        KLine:
        {
            DragMode: 1,                 //拖拽模式 0 禁止拖拽 1 数据拖拽 2 区间选择
            Right: 1,                    //复权 0 不复权 1 前复权 2 后复权
            Period: 0,                   //周期 0 日线 1 周线 2 月线 3 年线
            MaxReqeustDataCount: 1000,   //数据个数
            PageSize: 30,               //一屏显示多少数据
            Info: ["业绩预告", "公告", "互动易", "调研", "大宗交易", "龙虎榜"],       //信息地雷
            //Policy: ["30天地量", "20日均线,上穿62日均线"],  //策略信息
            InfoDrawType:0,
            DrawType: 0,
        },

        //叠加股票
        Overlay:
        [
            //{Symbol:'000001.sz'}
        ],

        KLineTitle: //标题设置
        {
            IsShowName: true,       //显示股票名称
            IsShowSettingInfo: true, //显示周期/复权
         },

        Border: //边框
        {
            Left: 1,    //左边间距
            Right: 1,     //右边间距
            Top:30,
            Bottom:25,
        },

        Frame:  //子框架设置
        [
            { SplitCount: 3 },
            { SplitCount: 2 },
            { SplitCount: 2 },
         ],

        ExtendChart:    //扩展图形
        [
            { Name: 'KLineTooltip' }
        ],
    },

    onLoad: function ()
     {
       var self = this

      // 获取系统信息
      wx.getSystemInfo({
        success: function (res) 
        {
            console.log(res);
            // 可使用窗口宽度、高度
            console.log('height=' + res.windowHeight);
            console.log('width=' + res.windowWidth);
            self.setData({ Height: res.windowHeight, Width: res.windowWidth, Title: { Display:'block'}});
        }
      });

    },

    onReady: function () 
    {
        //创建历史K线类
        var element = new JSCommon.JSCanvasElement();
        element.ID = 'historychart';

        element.Height = this.data.Height;   //高度宽度需要手动绑定!! 微信没有元素类
        element.Width = this.data.Width;
        this.HistoryChart = JSCommon.JSChart.Init(element); //把画布绑定到行情模块中

        this.HistoryChart.SetOption(this.HistoryOption);
    },
    
    //把画图事件绑定到hqchart控件上 
    historytouchstart: function (event) 
    {
      if (this.HistoryChart) this.HistoryChart.OnTouchStart(event);
    },
    historytouchmove: function (event) {
      if (this.HistoryChart) this.HistoryChart.OnTouchMove(event);
    },
    historytouchend: function (event) 
    {
      if (this.HistoryChart) this.HistoryChart.OnTouchEnd(event);
    },
  })

这样1个K线图就完成了。

如果还有问题可以加交流QQ群: 950092318

HQChart代码地址

地址:https://github.com/jones2000/HQChart

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
uniapp是一个基于Vue.js的跨平台开发框架,可以用于创建移动端应用程序。如果你想在uniapp中创建股票K线图,可以使用HQChart插件。首先,你需要创建一个uni-app工程,并将"umychart_uniapp_h5"目录拷贝到工程中。然后,在你的页面中引入"umychart.uniapp.h5.js"。通过这样的步骤,就可以在uni-app中使用HQChart插件创建K线图了。如果需要对接第三方数据,可以参考HQChart使用教程29和56,了解如何对接数据和品种代码的后缀列表。具体代码实现可以参考HQChart实战教程35和相关文件中的代码。如果你有更多的问题,可以加入交流QQ群950092318,获取更多帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [HQChart使用教程35 - 如何在uni-app创建K线图(h5)](https://blog.csdn.net/jones2000/article/details/101039026)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [HQChart实战教程35-A股分时图数据对接-uniapp版本](https://blog.csdn.net/jones2000/article/details/113777111)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HQChart

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值