123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <template>
- <view style="width: 100%;display: flex;align-items: center;">
- <view class="content">
- <view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" ref="chartId" :id="chartId" class="echarts"></view>
- </view>
- <view>
- <text style="font-size: 28rpx;font-family: Verdana, Verdana-Regular;font-weight: 400;text-align: left;color: #5f636f;">意向面积</text>
- <view style="display: flex;justify-content: space-between;margin-top: 10rpx;">
- <text style="font-size: 28rpx;font-family: Verdana, Verdana-Regular;font-weight: 400;text-align: left;" :style="{'color':fuzhuColor}" v-if="dataList.length > 0">{{dataList[0]}}m²</text>
- <text style="font-size: 28rpx;font-family: Verdana, Verdana-Regular;font-weight: 400;text-align: left; margin-left: 82rpx;" v-if="dataList.length > 1">{{dataList[1]}}m²</text>
- <text style="font-size: 28rpx;font-family: Verdana, Verdana-Regular;font-weight: 400;text-align: left; margin-left: 82rpx;" v-if="dataList.length > 2">{{dataList[2]}}m²</text>
- </view>
- </view>
- </view>
-
- </template>
- <script>
- import echarts from '../../static/echarts.js'
- var colorList = ['#FDD56A','#73ACFF','#73DDFF' ];
- export default {
- props: {
- chartId: String,
- title: {
- type: String,
- default: '面积'
- },
- dataList: {
- type: Array,
- default:() => {
- return []
- }
- }
- },
- data() {
- return {
- themeColor: "",
- fuzhuColor: "",
- themeColor25: "",
- option: {
- title: {
- text: '面积',
- x: 'center',
- y: 'center',
- textStyle: {
- fontSize: 10
- }
- },
- color: colorList,
- series: [{
- name: '访问来源',
- type: 'pie',
- radius: ['50%', '70%'],
- avoidLabelOverlap: false,
- hoverAnimation: false,
- label: {
- show: false,
- position: 'center'
- },
- itemStyle: {
- normal: {
- // color: function(params) {
- // return colorList[params.dataIndex]
- // }
- }
- },
- emphasis: {
- label: {
- show: false,
- fontSize: '30',
- fontWeight: 'bold'
- }
- },
- labelLine: {
- show: false
- },
- data: []
- // data: [{
- // value: 335,
- // name: '直接访问'
- // },
- // {
- // value: 310,
- // name: '邮件营销'
- // },
- // {
- // value: 234,
- // name: '联盟广告'
- // }
- // ]
- }]
- }
- }
- },
- methods: {
- getDataAction() {
- // this.dataList = []
- // this.data1 = []
- // for (var i = 0; i < 3; i++) {
- // var num1 = Math.ceil(Math.random() * 50)
- // this.data1.push(num1)
- // this.dataList.push(num1)
- // }
- this.option.series[0].data = this.dataList
- // this.option.xAxis.data = this.dataList
- // console.log('数据刷新面积', this.option.xAxis, this.dataList)
- },
- onViewClick(options) {
- // console.log(options)
- }
- },
- watch: {
- chartId: {
- handler(e) {
- // console.log('走没走!!!!', e)
- // this.getDataAction()
- },
- immediate: true
- },
- dataList: {
- handler(e) {
- this.getDataAction()
- },
- immediate: true
- }
- },
- mounted() {
- let app = getApp()
- let globalData = app.globalData;
- this.themeColor = globalData.themeColor
- this.fuzhuColor = globalData.fuzhuColor
- this.themeColor25 = globalData.themeColor25
- let that = this;
- }
- }
- </script>
- <script module="echarts" lang="renderjs">
- let myChart
- export default {
- mounted() {
- this.initAction()
- },
- methods: {
- initAction() {
- if (typeof window.echarts === 'function') {
- this.initEcharts()
- } else {
- // 动态引入较大类库避免影响页面展示
- const script = document.createElement('script')
- // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
- script.src = 'static/echarts.js'
- script.onload = this.initEcharts.bind(this)
- document.head.appendChild(script)
- }
- },
- initEcharts() {
- // console.log("initEcharts -> this.$refs", this.$refs.chartId.$el.id)
- myChart = echarts.init(document.getElementById(this.$refs.chartId.$el.id))
- // 观测更新的数据在 view 层可以直接访问到
- if(myChart){
- myChart.setOption(this.option)
- }
- },
- updateEcharts(newValue, oldValue, ownerInstance, instance) {
- // 监听 service 层数据变更
- if(myChart){
- myChart.setOption(newValue)
- }
-
- },
- onClick(event, ownerInstance) {
- // 调用 service 层的方法
- ownerInstance.callMethod('onViewClick', {
- test: 'test'
- })
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .content {
-
- .top-Section {
- padding: 0 20rpx;
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- font-family: Verdana;
- .title {
- font-size: 32rpx;
- font-weight: bold;
- color: #383838;
- }
- .rightBtn {
- font-size: 24rpx;
- color: #546074;
- margin-top: 5rpx;
- }
- }
- .echarts {
- width: 214rpx;
- margin-top: 0;
- height: 200rpx;
- }
- }
- </style>
|