From fde4daf5bf6ace15c3f78eb3bb5b9dbdad763674 Mon Sep 17 00:00:00 2001
From: zzzz <690498789@qq.com>
Date: Wed, 24 Apr 2024 21:37:54 +0800
Subject: [PATCH] first

---
 src/page/kline/components/kLine.vue |  137 +++++++++++++++++++++++++++------------------
 1 files changed, 81 insertions(+), 56 deletions(-)

diff --git a/src/page/kline/components/kLine.vue b/src/page/kline/components/kLine.vue
index 8ea56b0..cd4f695 100644
--- a/src/page/kline/components/kLine.vue
+++ b/src/page/kline/components/kLine.vue
@@ -1,33 +1,6 @@
 <template>
   <div class="box">
-    <!-- <div class="left">
-          <el-menu
-              default-active="AAPL.usa"
-              class="el-menu-vertical-demo"
-              background-color="#191919"
-              text-color="#dee4eb"
-              active-text-color="#ff6900"
-              :unique-opened="true"
-              @select='handleSelect'
-              @open="handleOpen"
-              @close="handleClose">
-              <el-submenu v-for="item in NavMenuAry" :key="item.Title" :index="item.Title">
-              <template slot="title">
-                  <i class="el-icon-menu"></i>
-                  <span>{{item.Title}}</span>
-              </template>
-                  <el-menu-item v-for="subItem in item.Sub" :key='subItem.Code' :index="subItem.Code">{{subItem.Name}}</el-menu-item>
-              </el-submenu>
-          </el-menu>
-    </div> -->
-
     <div class="right" ref="right">
-      <!-- <div class="rightTab" ref="rightTab">
-              <div class="btn showMinute" :class="{ active: chartType == 'minute' }"
-                  @click="changeRightContent('minute')">分时图</div>
-              <div class="btn showKline" :class="{ active: chartType == 'kline' }" @click="changeRightContent('kline')">
-                  K线图</div>
-      </div>-->
       <div class="rightContent" ref="rightContent">
         <div class="contentBox">
           <div class="periodWrap kline_periodWrap" ref="kline_periodWrap">
@@ -42,15 +15,7 @@
               >
                 <span>{{ item.Name }}</span>
               </div>
-              <div
-                class="btn2"
-                @click="isShow ? (isShow = false) : (isShow = true)"
-              >
-                <div class="btn2">
-                  <!-- :class="KLinePeriodIndex === index ? 'active' : ''" -->
-                  <img src="../../../assets/img/options.png" alt />
-                </div>
-              </div>
+
               <div
                 style="position: absolute; right: 0; top: 25px; z-index: 99"
                 v-if="isShow == true"
@@ -86,7 +51,7 @@
           <div
             class="hqchart"
             id="hqchart_minute"
-            ref="kline"
+            ref="mychart"
             v-show="chartType == 'minute'"
           ></div>
           <div
@@ -95,32 +60,22 @@
             ref="kline2"
             v-show="chartType == 'kline'"
           ></div>
-
-          <!-- <div class="statementWrap" ref="kline_statementWrap">
-                      郑重声明:本页面所有数据来自互联网或自动生成的测试数据,仅用于学习HQChart图形库使用,不构成任何投资价值信息。如使用者依据本网站提供的信息、资料及图表进行金融、证券等投资所造成的盈亏与本网站无关。
-          </div>-->
         </div>
       </div>
     </div>
-
-    <!-- <div class="right" ref="kline_right" >
-
-    </div>-->
   </div>
 </template>
 
 <script>
+import * as echarts from "echarts";
+
 import _ from "lodash";
 import HQChart from "hqchart";
 import "hqchart/src/jscommon/umychart.resource/css/tools.css";
 import "hqchart/src/jscommon/umychart.resource/font/iconfont.css";
 import EastMoney from "../../../eastmoney/HQData.js";
 import i18n from "@/locales/index.js";
-// 源码调试用
-// import Chart from '../jscommon/umychart.vue/umychart.vue.js'
-// import '../jscommon/umychart.resource/css/tools.css'
-// import '../jscommon/umychart.resource/font/iconfont.css'
-// var HQChart={ Chart:Chart };
+
 HQChart.Chart.MARKET_SUFFIX_NAME.GetMarketStatus = function (symbol) {
   return 2;
 }; // 一直交易
@@ -1061,6 +1016,7 @@
       VolChartHeight: 10,
       chartType: "kline",
       isShow: false,
+      xData: [],
     };
   },
   created() {
@@ -1080,6 +1036,7 @@
   },
 
   mounted() {
+    this.initEcharts();
     this.offHeight = this.$refs["rightContent"].offsetHeight;
     this.OnSize();
     this.SetChartStyle();
@@ -1121,6 +1078,70 @@
   },
 
   methods: {
+    // 横坐标数据处理
+    initxData() {
+      for (let i = 0; i < this.klineData.length; i++) {
+        this.xData[i] = this.klineData[i].datetime;
+      }
+    },
+    // 数据计算以及拆分,将json数据转为数组数据
+    splitData(jsonData) {
+      const hourData = [];
+      for (let i = 0; i < jsonData.length; i++) {
+        hourData.push([
+          i,
+          jsonData[i].price,
+          jsonData[i].increase,
+          jsonData[i].volume,
+          jsonData[i].ratio,
+          jsonData[i].amount,
+          jsonData[i].datetime,
+        ]);
+      }
+      this.hourData = hourData;
+    },
+    initEcharts() {
+      const option = {
+        // 横坐标数据配置
+        xAxis: [
+          {
+            type: "category",
+            data: this.xData,
+            boundaryGap: false,
+            axisLine: { onZero: false },
+            splitLine: { show: false },
+            min: "dataMin",
+            max: "dataMax",
+          },
+        ],
+        // 纵坐标配置
+        yAxis: [
+          {
+            scale: true,
+            splitArea: {
+              show: true,
+            },
+          },
+        ],
+        //图形数据配置:
+        series: [
+          {
+            type: "line",
+            data: this.hourData,
+            symbol: "none", //无标记图案
+            lineStyle: {
+              width: 1,
+            },
+          },
+        ],
+      };
+      const myChart = echarts.init(this.$refs.mychart); // 图标初始化
+      myChart.setOption(option); // 渲染页面
+      //随着屏幕大小调节图表
+      window.addEventListener("resize", () => {
+        myChart.resize();
+      });
+    },
     OnSize() {
       var width = this.$refs.right.clientWidth;
       // var rightTab = this.$refs.rightTab
@@ -1155,7 +1176,8 @@
         HQChart.Chart.STYLE_TYPE_ID.WHITE_ID
       ); // 读取黑色风格配置
 
-      // blackStyle.UpBarColor = "rgba(0,0,0,1)";
+      blackStyle.UpBarColor = "#449b54"; //上涨
+      blackStyle.DownBarColor = "#e13b45";
       HQChart.Chart.JSChart.SetStyle(blackStyle);
     },
 
@@ -1221,11 +1243,14 @@
       item,
       type // K线周期
     ) {
-      // if (index !== 0) {  //分时额外处理才注释的
-      this.chartType = type;
-      this.KLinePeriodIndex = index;
-      this.KLineChart.ChangePeriod(item.ID);
-      // }
+      if (index !== 0) {
+        //分时额外处理才注释的
+        this.chartType = type;
+        this.KLinePeriodIndex = index;
+        this.KLineChart.ChangePeriod(item.ID);
+      } else {
+        this.chartType = "minute";
+      }
     },
 
     OnClickKLineRightMenu(

--
Gitblit v1.9.3