一、(1)插件市场,导入使用renderjs
<!-- 列表页 -->
<template>
<view>
<!-- 2 start -->
<view class="sales-view">
<sale-column-chart :chartData="chartDataObj02"></sale-column-chart>
</view>
<!-- 2 end -->
</view>
</template>
<script>
import saleColumnChart from '@/components/echarts/index.vue';
export default {
components: {
saleColumnChart
},
data(){
return{
chartDataObj02:{
categories:['1','2','3','4','5','6','7','8','9','10','11','12'],
series:[
{
barWidth: 10,
color: "#4B7ED4",
name: "实收",
stack: "Ad",
type: "bar",
yAxisIndex: 1,
data:["0.00","0.00","0.00","20724.97","30529.00","43640.88","13428.60","0.00","0.00","0.00" ,"0.00" ,"0.00"],
itemStyle:{barBorderRadius:[2,2,0,0]}
},
{
barWidth: 10,
color: "#D5E2F7",
name: "应收",
stack: "Ad",
type: "bar",
yAxisIndex: 1,
data:["0.00","0.00","0.00","20724.97","30529.00","43640.88","13428.60","0.00","0.00","0.00" ,"0.00" ,"0.00"],
itemStyle:{barBorderRadius:[2,2,0,0]}
},
{
barWidth: 10,
color: "#47D1E3",
name: "回款率",
stack: "Ad",
type: "line",
yAxisIndex: 0,
data:["0.00","0.00","0.00","0.00","1060.15","485.31","451.82","136.41","0.00","0.00" ,"0.00" ,"0.00"],
itemStyle:{barBorderRadius:[2,2,0,0]}
},
]
},
}
},
onLoad() {
},
methods:{
getTreeIndexTap(row){
console.log('----',row)
}
},
}
</script>
<style lang="scss" scoped>
page{
background-color: #f6f7fb;
}
.sales-view{
margin: 20rpx;
border-radius: 16rpx;
background-color: white;
padding: 20rpx;
.title{
font-size: 26rpx;
}
}
</style>

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
一、(2)封装组件
<!-- uniapp插件市场 renderjs-echarts-demo -->
<template>
<view class="content">
<!-- #ifdef APP-PLUS || H5 -->
<view v-if="Object.keys(option).length > 0" @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" id="echarts" class="echarts"></view>
<!-- <button @click="changeOption">更新数据</button> -->
<!-- #endif -->
</view>
</template>
<script>
export default {
props: {
chartData: {
type: Object
},
axisLabelShow: {
type: Boolean,
default: true
},
rotate: {
type: [String, Number],
default: 0
}
},
data() {
return {
option: {}
};
},
mounted() {
this.$nextTick(() => {
if (Object.keys(this.chartData).length > 0) {
this.option = {
tooltip: {
show: false,
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
legend: {
icon: 'circle',
textStyle: {
color: '#BEC1CD',
fontSize: 12
},
x: 'right'
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [
{
axisTick: {
show: false
},
type: 'category',
splitLine: { show: false },
data: this.chartData.categories,
axisLine: {
show: true,
lineStyle: {
color: '#F0F0F0',
fontSize: 12
}
},
axisLabel: {
show: true,
rotate: this.rotate,
interval: 0,
textStyle: {
color: '#B7BAC6'
}
}
}
],
yAxis: [
{
type: 'value',
position: 'left',
alignTicks: true,
axisTick: {
show: false
},
splitLine: {
lineStyle: {
type: 'border',
color: '#EEEEEE'
},
show: true
},
axisLine: {
show: false,
lineStyle: {
color: '#BEC1CD',
fontSize: 12
}
},
axisLabel: {
formatter: this.axisLabelShow ? '{value}%' : '{value}'
}
},
{
type: 'value',
position: 'right',
alignTicks: true,
axisTick: {
show: false
},
axisLine: {
show: false,
lineStyle: {
color: '#BEC1CD'
}
},
splitLine: {
lineStyle: {
color: '#EEEEEE',
type: 'border'
},
show: false
},
axisLabel: {
show: this.axisLabelShow,
formatter: this.axisLabelShow ? '{value}万' : '{value}'
}
}
],
series: this.chartData.series
};
}
});
},
methods: {
changeOption() {
const data = this.option.series[0].data;
data.forEach((item, index) => {
data.splice(index, 1, Math.random() * 40);
});
},
onViewClick(options) {
console.log(options);
}
}
};
</script>
<script module="echarts" lang="renderjs">
let myChart
export default {
mounted() {
if (typeof window.echarts === 'function') {
this.initEcharts()
} else {
const script = document.createElement('script')
script.src = 'static/echarts.js'
script.onload = this.initEcharts.bind(this)
document.head.appendChild(script)
}
},
methods: {
initEcharts() {
myChart = echarts.init(document.getElementById('echarts'))
myChart.setOption(this.option)
},
updateEcharts(newValue, oldValue, ownerInstance, instance) {
if(myChart){
myChart.setOption(newValue)
}
},
onClick(event, ownerInstance) {
ownerInstance.callMethod('onViewClick', {
option: this.option
})
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.echarts {
width: 100%;
height: 300px;
}
</style>

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216