From 155f2b80f2a9b6f900c73f6e4461e9cebb7cd028 Mon Sep 17 00:00:00 2001 From: whycq <10027870+whycq@user.noreply.gitee.com> Date: 星期二, 10 十月 2023 17:12:20 +0800 Subject: [PATCH] # --- package-lock.json | 34 ++ pages.json | 11 components/echarts/echarts.vue | 179 +++++++++++ package.json | 5 pages/index/echarts.vue | 667 +++++++++++++++++++++++++++++++++++++++++ pages/index/index.vue | 5 6 files changed, 898 insertions(+), 3 deletions(-) diff --git a/components/echarts/echarts.vue b/components/echarts/echarts.vue new file mode 100644 index 0000000..613abf6 --- /dev/null +++ b/components/echarts/echarts.vue @@ -0,0 +1,179 @@ +<template> + <view> + <view class="echarts" :prop="option" :change:prop="echarts.update"></view> + </view> +</template> + +<script> + export default { + name: 'Echarts', + props: { + option: { + type: Object, + required: true + } + } + } +</script> + +<script module="echarts" lang="renderjs"> + export default { + data() { + return { + chart: null + } + }, + mounted() { + if (typeof window.echarts === 'object') { + this.init() + } else { + // 鍔ㄦ�佸紩鍏ョ被搴� + const script = document.createElement('script') + script.src = './static/echarts.min.js' + // script.src = './static/echarts/echarts.min.js' + script.onload = this.init + document.head.appendChild(script) + } + }, + methods: { + /** + * 鍒濆鍖杄charts + */ + init() { + this.chart = echarts.init(this.$el) + this.update(this.option) + }, + /** + * 鐩戞祴鏁版嵁鏇存柊 + * @param {Object} option + */ + update(option) { + if (this.chart) { + // 鍥燗pp绔紝鍥炶皟鍑芥暟鏃犳硶浠巖enderjs澶栦紶閫掞紝鏁呭湪姝よ嚜瀹氫箟璁剧疆鐩稿叧鍥炶皟鍑芥暟 + if (option) { + // tooltip + if (option.tooltip) { + // 鍒ゆ柇鏄惁璁剧疆tooltip鐨勪綅缃� + if (option.tooltip.positionStatus) { + option.tooltip.position = this.tooltipPosition() + } + // 鍒ゆ柇鏄惁鏍煎紡鍖杢ooltip + if (option.tooltip.formatterStatus) { + option.tooltip.formatter = this.tooltipFormatter(option.tooltip.formatterUnit, option.tooltip.formatFloat2, option.tooltip.formatThousands) + } + } + // 璁剧疆鏂扮殑option + this.chart.setOption(option, option.notMerge) + } + + } + }, + /** + * 璁剧疆tooltip鐨勪綅缃紝闃叉瓒呭嚭鐢诲竷 + */ + tooltipPosition() { + return (point, params, dom, rect, size) => { + //鍏朵腑point涓哄綋鍓嶉紶鏍囩殑浣嶇疆锛宻ize涓湁涓や釜灞炴�э細viewSize鍜宑ontentSize锛屽垎鍒负澶栧眰div鍜宼ooltip鎻愮ず妗嗙殑澶у皬 + let x = point[0] + let y = point[1] + let viewWidth = size.viewSize[0] + let viewHeight = size.viewSize[1] + let boxWidth = size.contentSize[0] + let boxHeight = size.contentSize[1] + let posX = 0 //x鍧愭爣浣嶇疆 + let posY = 0 //y鍧愭爣浣嶇疆 + if (x < boxWidth) { //宸﹁竟鏀句笉寮� + posX = 5 + } else { //宸﹁竟鏀剧殑涓� + posX = x - boxWidth + } + if (y < boxHeight) { //涓婅竟鏀句笉寮� + posY = 5 + } else { //涓婅竟鏀惧緱涓� + posY = y - boxHeight + } + return [posX, posY] + } + }, + /** + * tooltip鏍煎紡鍖� + * @param {Object} unit 鏁板�煎悗鐨勫崟浣� + * @param {Object} formatFloat2 鏄惁淇濈暀涓や綅灏忔暟 + * @param {Object} formatThousands 鏄惁娣诲姞鍗冨垎浣� + */ + tooltipFormatter(unit, formatFloat2, formatThousands) { + return params => { + let result = '' + unit = unit ? unit : '' + for (let i in params) { + if (i == 0) { + result += params[i].axisValueLabel + } + let value = '--' + if (params[i].data !== null) { + value = params[i].data + // 淇濈暀涓や綅灏忔暟 + if (formatFloat2) { + value = this.formatFloat2(value) + } + // 娣诲姞鍗冨垎浣� + if (formatThousands) { + value = this.formatThousands(value) + } + } + // #ifdef H5 + result += '\n' + params[i].seriesName + '锛�' + value + ' ' + unit + // #endif + + // #ifdef APP-PLUS + result += '<br/>' + params[i].marker + params[i].seriesName + '锛�' + value + ' ' + unit + // #endif + } + return result + } + }, + /** + * 淇濈暀涓や綅灏忔暟 + * @param {Object} value + */ + formatFloat2(value) { + let temp = Math.round(parseFloat(value) * 100) / 100 + let xsd = temp.toString().split('.') + if (xsd.length === 1) { + temp = (isNaN(temp) ? '0' : temp.toString()) + '.00' + return temp + } + if (xsd.length > 1) { + if (xsd[1].length < 2) { + temp = temp.toString() + '0' + } + return temp + } + }, + /** + * 娣诲姞鍗冨垎浣� + * @param {Object} value + */ + formatThousands(value) { + if (value === undefined || value === null) { + value = '' + } + if (!isNaN(value)) { + value = value + '' + } + let re = /\d{1,3}(?=(\d{3})+$)/g + let n1 = value.replace(/^(\d+)((\.\d+)?)$/, function(s, s1, s2) { + return s1.replace(re, '$&,') + s2 + }) + return n1 + } + } + } +</script> + +<style lang="scss" scoped> + .echarts { + width: 100%; + height: 100%; + } +</style> \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..b449893 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,34 @@ +{ + "name": "crm_app", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "echarts": "^5.4.3" + } + }, + "node_modules/echarts": { + "version": "5.4.3", + "resolved": "https://registry.npmjs.org/echarts/-/echarts-5.4.3.tgz", + "integrity": "sha512-mYKxLxhzy6zyTi/FaEbJMOZU1ULGEQHaeIeuMR5L+JnJTpz+YR03mnnpBhbR4+UYJAgiXgpyTVLffPAjOTLkZA==", + "dependencies": { + "tslib": "2.3.0", + "zrender": "5.4.4" + } + }, + "node_modules/tslib": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" + }, + "node_modules/zrender": { + "version": "5.4.4", + "resolved": "https://registry.npmjs.org/zrender/-/zrender-5.4.4.tgz", + "integrity": "sha512-0VxCNJ7AGOMCWeHVyTrGzUgrK4asT4ml9PEkeGirAkKNYXYzoPJCLvmyfdoOXcjTHPs10OZVMfD1Rwg16AZyYw==", + "dependencies": { + "tslib": "2.3.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..faa4886 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "echarts": "^5.4.3" + } +} diff --git a/pages.json b/pages.json index 4c9cafe..2974ee9 100644 --- a/pages.json +++ b/pages.json @@ -156,7 +156,16 @@ - ], + ,{ + "path" : "pages/index/echarts", + "style" : + { + "navigationBarTitleText": "echarts", + "enablePullDownRefresh": false + } + + } + ], "globalStyle": { "navigationBarTextStyle": "black", // "navigationBarTitleText": "CRM", diff --git a/pages/index/echarts.vue b/pages/index/echarts.vue new file mode 100644 index 0000000..102e9e8 --- /dev/null +++ b/pages/index/echarts.vue @@ -0,0 +1,667 @@ + +<template> + <view class="viewimg"> + <view> + <view>echarts绀哄垪</view> + <echarts :option="option" style="height: 300px;"></echarts> + <button @click="updateClick">鏇存柊鏁版嵁</button> + </view> + <view> + <echarts :option="optionone" style="height: 400px;"></echarts> + </view> + <view> + <echarts :option="optiontwo" style="height: 400px;"></echarts> + </view> + </view> +</template> + +<script> + import echarts from '@/components/echarts/echarts.vue'; + export default { + data() { + return { + option: {}, + optionone: {}, + optiontwo: {} + }; + }, + onLoad() { + // console.log(777777); + }, + components: { + echarts + }, + mounted() { + this.logstatrt(); + this.logstatrtone(); + this.logstatrttwo(); + }, + methods: { + logstatrt() { + // console.log('鍒濇璋冪敤'); + this.option = { + backgroundColor: '#011246', + tooltip: { + trigger: 'axis', + axisPointer: { + type: 'shadow' + } + }, + grid: { + top: '25%', + right: '45', + bottom: '20', + left: '30' + }, + legend: { + data: [{ + name: '浜轰繚' + }, { + name: '澶繚' + }, { + name: '骞冲畨' + }, { + name: '浜轰繚澧為��' + }, { + name: '澶繚澧為��' + }, { + name: '骞冲畨澧為��' + }], + top: '0%', + textStyle: { + color: 'rgba(255,255,255,0.9)' //鍥句緥鏂囧瓧 + } + }, + dataZoom: [{ + type: 'slider', + realtime: true, + //绉诲姩绔睍绀烘柟寮� + handleSize: '100%', //婊戝姩鏉′袱渚х殑澶у皬 + start: 0, + end: 50 + }], + grid: { + left: '3%', + right: '4%', + bottom: '15%', + height: '70%', + containLabel: true + }, + xAxis: [{ + type: 'category', + data: ['2015', '2016', '2017', '2018', '2019'], + axisLine: { + lineStyle: { + color: 'rgba(255,255,255,.1)' + } + }, + axisLabel: { + textStyle: { + color: 'rgba(255,255,255,.7)', + fontSize: '14' + } + } + }], + yAxis: [{ + type: 'value', + name: '鍗曚綅涓�', + splitLine: { + show: false + }, + axisLabel: { + show: true, + fontSize: 14, + color: 'rgba(255,255,255,.6)' + }, + axisLine: { + min: 0, + max: 10, + lineStyle: { + color: 'rgba(255,255,255,.4)' + } + } //宸︾嚎鑹� + }, + { + type: 'value', + name: '澧為��', + show: true, + axisLabel: { + show: true, + fontSize: 14, + formatter: '{value} %', + color: 'rgba(255,255,255,.6)' + }, + axisLine: { + lineStyle: { + color: 'rgba(255,255,255,.4)' + } + }, //鍙崇嚎鑹� + splitLine: { + show: true, + lineStyle: { + color: 'rgba(255,255,255,.1)' + } + } //x杞寸嚎 + } + ], + series: [{ + name: '浜轰繚', + type: 'bar', + data: [35, 36.6, 38.8, 40.84, 41.6], + // "barWidth": "30", + itemStyle: { + normal: { + color: { + type: 'linear', + x: 0.5, + y: 0.5, + r: 0.5, + colorStops: [{ + offset: 0, + color: '#00FFE3' // 0% 澶勭殑棰滆壊 + }, + { + offset: 1, + color: '#4693EC' // 100% 澶勭殑棰滆壊 + } + ], + globalCoord: false // 缂虹渷涓� false + } + } + } + // "barGap": "0.2" + }, + { + name: '澶繚', + type: 'bar', + data: [16, 14.8, 14.1, 15, 16.3], + + color: { + type: 'linear', + x: 0.5, + y: 0.5, + r: 0.5, + colorStops: [{ + offset: 0, + color: '#248ff7' // 0% 澶勭殑棰滆壊 + }, + { + offset: 1, + color: '#6851f1' // 100% 澶勭殑棰滆壊 + } + ], + globalCoord: false // 缂虹渷涓� false + } + }, + { + name: '骞冲畨', + type: 'bar', + data: [10.2, 9.2, 9.1, 9.85, 8.9], + color: { + type: 'linear', + x: 0.5, + y: 0.5, + r: 0.5, + colorStops: [{ + offset: 0, + color: '#fccb05' // 0% 澶勭殑棰滆壊 + }, + { + offset: 1, + color: '#f5804d' // 100% 澶勭殑棰滆壊 + } + ], + globalCoord: false // 缂虹渷涓� false + } + }, + { + name: '浜轰繚澧為��', + type: 'line', + yAxisIndex: 1, + + data: [0, 6.01, 5.26, 1.48], + lineStyle: { + normal: { + width: 2 + } + }, + itemStyle: { + normal: { + color: '#86d370' + } + }, + smooth: true + }, + { + name: '澶繚澧為��', + type: 'line', + yAxisIndex: 1, + + data: [0, -4.73, 6.38, 8.67], + lineStyle: { + normal: { + width: 2 + } + }, + itemStyle: { + normal: { + color: '#3496f8' + } + }, + smooth: true + }, + { + name: '骞冲畨澧為��', + type: 'line', + yAxisIndex: 1, + + data: [0, -1.09, 8.24, -9.64], + lineStyle: { + normal: { + width: 2 + } + }, + itemStyle: { + normal: { + color: '#fbc30d' + } + }, + smooth: true + } + ] + }; + }, + logstatrtone() { + this.optionone = { + backgroundColor: '#0c1e55', + + color: ['#00a0fc', '#ffe400', '#ff9a09', '#ef1e5f', '#23cbe5', '#ec561b', '#ffa500', '#dddf00', '#b23aee', + '#50b332' + ], + + tooltip: { + trigger: 'item', + // formatter: " {a} <br/>{b} : {c} ({d}%)" + formatter: " 浼佷笟鏁帮細{c}" + }, + legend: { // 鍥句緥-鍥句笂闈㈢殑鍒嗙被 + // orient: 'vertical', + // right: 30, + // icon: 'rect',//闀挎柟褰� + icon: 'circle', + top: "1%", + itemWidth: 10, + itemHeight: 10, + // itemGap: 13, + data: ['16鈩冧互涓�', '16-18鈩�', '18-20鈩�', '20-22鈩�', '22-24鈩�', '24-26鈩�', '26鈩冧互涓�'], + // right: '56%', + textStyle: { + fontSize: 14, + color: '#a6cde8', + lineHeight: 49 + }, + formatter: function(name) { + return "" + name + "" + }, + padding: [2, 2] + }, + grid: { + top: '20%', + left: '53%', + right: '10%', + bottom: '6%', + containLabel: true + }, + + series: [{ + label: { + normal: { + formatter: '{b|{b}锛殅 {c} \n {per|{d}%} ', + rich: {} + }, + emphasis: { + show: true, + } + }, + // labelLine: { + // normal: { + // show: false + // } + // }, + name: '璁块棶鏉ユ簮', + type: 'pie', + radius: '55%', + center: ['50%', '60%'], + data: [{ + value: 195, + name: '16鈩冧互涓�' + }, + { + value: 185, + name: '16-18鈩�' + }, + { + value: 260, + name: '18-20鈩�' + }, + { + value: 213, + name: '20-22鈩�' + }, + { + value: 52, + name: '22-24鈩�' + }, + { + value: 35, + name: '24-26鈩�' + }, + { + value: 46, + name: '26鈩冧互涓�' + }, + ], + itemStyle: { + emphasis: { + shadowBlur: 10, + shadowOffsetX: 0, + shadowColor: 'rgba(0, 0, 0, 0.5)' + } + }, + labelLine: { + normal: { + length: 5, + length2: 1, + smooth: true, + } + }, + }] + }; + }, + logstatrttwo() { + var m2R2Data = [{ + value: 335, + value1: 234, + legendname: '鈪犵被', + name: "鈪犵被", + itemStyle: { + color: "#8d7fec" + } + }, + { + value: 310, + value1: 314, + legendname: '鈪$被', + name: "鈪$被", + itemStyle: { + color: "#5085f2" + } + }, + { + value: 234, + value1: 235, + legendname: '鈪㈢被', + name: "鈪㈢被", + itemStyle: { + color: "#e75fc3" + } + }, + { + value: 154, + value1: 213, + legendname: '鈪g被', + name: "鈪g被", + itemStyle: { + color: "#f87be2" + } + }, + { + value: 335, + value1: 321, + legendname: '鈪ょ被', + name: "鈪ょ被", + itemStyle: { + color: "#f2719a" + } + }, + + ]; + + this.optiontwo = { + title: [{ + text: '鍏ㄧ綉璋冩帶鎯呭喌', + textStyle: { + fontSize: 16, + color: "black" + }, + left: "35%" + }, + { + text: '鍏ㄧ綉鍧囨俯', + subtext: 44.5 + '鈩�', + textStyle: { + fontSize: 15, + color: "black" + }, + subtextStyle: { + fontSize: 20, + color: 'black' + }, + textAlign: "center", + x: '40%', + y: '44%', + } + ], + tooltip: { + trigger: 'item', + formatter: function(parms) { + var str = parms.seriesName + "</br>" + + parms.marker + "" + parms.data.legendname + "</br>" + + "褰撳墠娓╁害锛�" + parms.data.value + "</br>" + + "鐩爣娓╁害锛�" + parms.data.value1 + "</br>" + + "鍗犳瘮锛�" + parms.percent + "%"; + return str; + } + }, + legend: { + type: "scroll", + orient: 'vertical', + left: '80%', + align: 'left', + top: 'middle', + textStyle: { + color: '#8C8C8C' + }, + + }, + series: [{ + name: '鍏ㄧ綉璋冩帶鎯呭喌', + type: 'pie', + center: ['40%', '50%'], + radius: ['40%', '65%'], + clockwise: false, //楗煎浘鐨勬墖鍖烘槸鍚︽槸椤烘椂閽堟帓甯� + avoidLabelOverlap: false, + itemStyle: { //鍥惧舰鏍峰紡 + normal: { + borderColor: '#ffffff', + borderWidth: 1, + }, + }, + label: { + normal: { + show: true, + position: 'outter', + formatter: function(parms) { + return parms.data.legendname + } + } + }, + labelLine: { + normal: { + length: 15, + length2: 13, + smooth: true, + } + }, + data: m2R2Data + }] + }; + }, + /** + * 鏇存柊鏁版嵁 + */ + updateClick() { + this.option.series=[{ + name: '浜轰繚', + type: 'bar', + data: [10, 10, 10, 10, 10], + // "barWidth": "30", + itemStyle: { + normal: { + color: { + type: 'linear', + x: 0.5, + y: 0.5, + r: 0.5, + colorStops: [{ + offset: 0, + color: '#00FFE3' // 0% 澶勭殑棰滆壊 + }, + { + offset: 1, + color: '#4693EC' // 100% 澶勭殑棰滆壊 + } + ], + globalCoord: false // 缂虹渷涓� false + } + } + } + // "barGap": "0.2" + }, + { + name: '澶繚', + type: 'bar', + data: [16, 14.8, 14.1, 15, 16.3], + + color: { + type: 'linear', + x: 0.5, + y: 0.5, + r: 0.5, + colorStops: [{ + offset: 0, + color: '#248ff7' // 0% 澶勭殑棰滆壊 + }, + { + offset: 1, + color: '#6851f1' // 100% 澶勭殑棰滆壊 + } + ], + globalCoord: false // 缂虹渷涓� false + } + }, + { + name: '骞冲畨', + type: 'bar', + data: [10.2, 9.2, 9.1, 9.85, 8.9], + color: { + type: 'linear', + x: 0.5, + y: 0.5, + r: 0.5, + colorStops: [{ + offset: 0, + color: '#fccb05' // 0% 澶勭殑棰滆壊 + }, + { + offset: 1, + color: '#f5804d' // 100% 澶勭殑棰滆壊 + } + ], + globalCoord: false // 缂虹渷涓� false + } + }, + { + name: '浜轰繚澧為��', + type: 'line', + yAxisIndex: 1, + + data: [0, 6.01, 5.26, 1.48], + lineStyle: { + normal: { + width: 2 + } + }, + itemStyle: { + normal: { + color: '#86d370' + } + }, + smooth: true + }, + { + name: '澶繚澧為��', + type: 'line', + yAxisIndex: 1, + + data: [0, -4.73, 6.38, 8.67], + lineStyle: { + normal: { + width: 2 + } + }, + itemStyle: { + normal: { + color: '#3496f8' + } + }, + smooth: true + }, + { + name: '骞冲畨澧為��', + type: 'line', + yAxisIndex: 1, + + data: [0, -1.09, 8.24, -9.64], + lineStyle: { + normal: { + width: 2 + } + }, + itemStyle: { + normal: { + color: '#fbc30d' + } + }, + smooth: true + } + ] + // this.option = { + // notMerge: true, // 鑷畾涔夊彉閲忥細true浠h〃涓嶅悎骞舵暟鎹紝姣斿浠庢姌绾垮浘鍙樹负鏌卞舰鍥惧垯闇�璁剧疆涓簍rue锛沠alse鎴栦笉鍐欎唬琛ㄥ悎骞� + // xAxis: { + // type: 'category', + // data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] + // }, + // yAxis: { + // type: 'value' + // }, + // series: [{ + // data: [120, 200, 150, 80, 70, 110, 130], + // type: 'bar', + // showBackground: true, + // backgroundStyle: { + // color: 'rgba(220, 220, 220, 0.8)' + // } + // }] + // }; + } + } + }; +</script> +<style> + .viewimg { + height: 100%; + /* background: #d1e9e9; */ + } +</style> + diff --git a/pages/index/index.vue b/pages/index/index.vue index 315a8ea..7995f1e 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -1,6 +1,7 @@ <template> <view> - <view class="box" :class="it.bg" v-for="it in mainItem"> + + <!-- <view class="box" :class="it.bg" v-for="it in mainItem"> <view class="box-title">{{it.title}}</view> <view class="box-item"> <view class="item-title">{{it.subTitle}}</view> @@ -24,7 +25,7 @@ <view style="flex: 3;text-align: end;"><text>{{item.performance}}</text></view> </view> </view> - </view> + </view> --> </view> </template> -- Gitblit v1.9.1