123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <template>
- <view class="content">
- <view @click="echarts.onClick" :change:prop="echarts.updateEcharts" id="echarts" class="echarts"></view>
- </view>
- </template>
- <script>
- export default {
- name: 'chart',
- props: {
- fbindData: {
- type: Object,
- default: null
- }
- },
-
- computed: {
- bindData() {
- return this.fbindData;
- },
-
-
- },
- data() {
-
- return {
- aa:0
- }
- },
- onLoad() {
-
-
-
- },
- methods: {
- 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')
- // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
- script.src = 'static/echarts.min.js'
- script.onload = this.initEcharts.bind(this)
- document.head.appendChild(script)
- }
- },
- methods: {
- initEcharts() {
- console.log('子组件bindData.fire_water_count')
- console.log(this.bindData.fire_water_count)
- var dataname = ['消防水系统', '报警主机', '电气火灾', '其他', '监控视频']
- var datavaule = [this.bindData.fire_water_count, this.bindData.alarm_host_count, this.bindData.electrical_fire_count, this.bindData.other_count, this.bindData.video_monitoring_count]
- var aa = [this.bindData.fire_water_count, this.bindData.alarm_host_count, this.bindData.electrical_fire_count, this.bindData.other_count, this.bindData.video_monitoring_count]
- aa.sort(function (a, b) {
- return a-b;
- });
- aa=aa.pop();
- var datamax = [aa, aa, aa, aa, aa];
- var color = ['#3C8BF0', '#06CDF8', '#0ECB70', '#6744EF', '#FFD803'];
-
- var indicator = []
-
- for (var i = 0; i < dataname.length; i++) {
- indicator.push({
- name: dataname[i],
- max: datamax[i],
- color: color[i]
- })
- }
-
- function contains(arrays, obj) {
- var i = arrays.length;
- while (i--) {
- if (arrays[i] === obj) {
- return i;
- }
- }
- return false;
- }
- myChart = echarts.init(document.getElementById('echarts'))
- // 观测更新的数据在 view 层可以直接访问到
- myChart.setOption({
- tooltip: {
- formatter: function() {
- var html = '';
- for (var i = 0; i < datavaule.length; i++) {
- html += dataname[i] + ' : ' + datavaule[i] + '\n'
- }
- return html
- }
- },
- radar: {
- center: ["50%", "50%"],
- radius: "72%",
- splitArea: {
- areaStyle: {
- color: [
- '#6494fe', '#d1dfff',
- '#6494fe', '#d1dfff',
- ]
- }
- },
- axisLabel: {
- show: false,
- },
- axisLine: {
- show: true,
- lineStyle: {
- color: "rgba(255,255,255,.5)",
- }
- },
- splitLine: {
- lineStyle: {
- color: '#fff', // 分隔线颜色
- width: 1 // 分隔线线宽
- }
- },
- name: {
- formatter: function(value) {
- var i = contains(dataname, value);
- var percent = datavaule[i];
- return '{a|' + value + '}\n ' + '{b|' + percent + '}'
- },
- textStyle: {
- rich: {
- a: {
- // color: '#333',
- fontSize: 13,
- align: 'center',
- padding: [-5, 0, 0, 0]
- },
- b: {
- // color: 'red',
- fontSize: 13,
- align: 'center',
- padding: [-18, 0, 0, -7]
- }
- },
- },
- },
- indicator: indicator
- },
- series: [{
- type: "radar",
- symbol: "circle",
- symbolSize: 7,
- areaStyle: {
- normal: {
- color: 'rgba(255,2,2, 0.5)',
- },
- },
- itemStyle: {
- color: '#fff',
- borderColor: '#ff0202',
- borderWidth: 1,
- },
- lineStyle: {
- normal: {
- color: "#ff0202",
- width: 1
- }
- },
- data: [datavaule]
- }]
- })
- },
- updateEcharts(newValue, oldValue, ownerInstance, instance) {
- // 监听 service 层数据变更
- myChart.setOption(newValue)
- },
- onClick(event, ownerInstance) {
- // 调用 service 层的方法
- ownerInstance.callMethod('onViewClick', {
- test: 'test'
- })
- }
- }
- }
- </script>
- <style>
- .content {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- }
- .echarts {
- width: 100%;
- height: 500rpx;
- margin-top: 70rpx;
- /* background:pink */
- }
- </style>
|