123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- // pages/skinRecord/components/analysis/analysis.js
- import * as echarts from '../../../../components/local/ec-canvas/echarts'
- import { getPrePage } from '../../../../utils/util'
- Component({
- /**
- * 组件的属性列表
- */
- options: {
- addGlobalClass: true,
- },
- properties: {
- analysis: {
- type: Object,
- value: null,
- observer(newVal, oldVal) {
- if (newVal && this.data.current == 0) {
- console.log(this.data.current)
- this.init()
- }
- },
- },
- current: {
- type: String,
- value: '',
- observer(newVal) {
- if (this.data.analysis && newVal == 0) {
- this.init()
- }
- },
- },
- },
- /**
- * 组件的初始数据
- */
- data: {
- percent: 0,
- ec: {
- lazyLoad: true,
- },
- },
- lifetimes: {
- attached: function () {
- this.setData({
- percent: 80,
- })
- // this.init()
- },
- detached: function () {
- // 在组件实例被从页面节点树移除时执行
- },
- },
- /**
- * 组件的方法列表
- */
- methods: {
- init() {
- let radarVal = []
- let seriesVal = []
- this.data.analysis.data.forEach((item) => {
- radarVal.push({ name: item.name, max: 100 })
- seriesVal.push(item.score)
- })
- console.log(radarVal)
- console.log(seriesVal)
- this.ecComponent = this.selectComponent('#mychart-dom-bar')
- this.ecComponent.init((canvas, width, height, dpr) => {
- // 获取组件的 canvas、width、height 后的回调函数
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr, // new
- })
- var option = {
- backgroundColor: '#FFF8FB',
- color: ['#FA7D22', 'red'],
- xAxis: {
- show: false,
- },
- yAxis: {
- show: false,
- },
- radar: {
- shape: 'circle',
- splitNumber: 4,
- indicator: radarVal,
- axisName: {
- // formatter: '【{value}】',
- color: '#333333',
- fontSize: 10,
- },
- splitArea: {
- areaStyle: {
- color: [
- 'rgba(218, 252, 191, 0.35)',
- 'rgba(255, 233, 185, 0.34)',
- 'rgba(255, 226, 208, 0.36)',
- 'rgba(255, 237, 237, 0.43)',
- ],
- // shadowColor: 'rgba(0, 0, 0, 0.2)',
- // shadowBlur: 10
- },
- },
- axisLine: {
- lineStyle: {
- color: '#fff',
- },
- },
- splitLine: {
- lineStyle: {
- color: 'transparent',
- },
- },
- },
- series: [
- {
- name: '预算 vs 开销',
- type: 'radar',
- data: [
- {
- value: seriesVal,
- areaStyle: {
- color: '#FA7D22',
- },
- lineStyle: {
- type: 'dotted',
- },
- label: {
- show: true,
- formatter: function (params) {
- return params.value
- },
- },
- },
- // {
- // value: [300, 430, 150, 300, 420, 250],
- // name: '开销'
- // },
- ],
- },
- ],
- }
- chart.setOption(option)
- // 将图表实例绑定到 this 上,可以在其他成员函数(如 dispose)中访问
- this.chart = chart
- // 注意这里一定要返回 chart 实例,否则会影响事件处理等
- return chart
- })
- },
- goToDetail() {
- getPrePage().setData(
- {
- current: 2,
- },
- () => {
- wx.pageScrollTo({
- scrollTop: 0,
- duration: 300,
- })
- }
- )
- },
- },
- })
|