<template>
<div ref="chart" class="xp-chart-radar"></div>
</template>

<script>
/**
 * @file chart-radar
 * @author zhangping15
 * @date 2018-06-15
 */
import * as echarts from 'echarts/lib/echarts';
import 'echarts/lib/chart/radar';
import 'echarts/lib/component/legend';
import 'echarts/lib/component/tooltip';

export default {
    name: 'chart-radar',
    data() {
        return {
            datasource: null,
            chart: {
                tooltip: {
                    trigger: 'item',
                    textStyle: {
                        fontSize: 12,
                        fontWeight: 100
                    }
                },
                color: ['#e098c7', '#00acee', '#0d72c2', '#fe8463', '#71669e', '#22c3aa'],
                legend: {
                    data: [],
                    x: 'center',
                    icon: 'rect',
                    itemWidth: 10,
                    itemHeight: 10,
                    itemGap: 25,
                    textStyle: {
                        color: '#333',
                        padding: [0, 0, 0, 5]
                    }
                },
                radar: {
                    shape: 'circle',
                    radius: '70%',
                    name: {
                        textStyle: {
                           color:'#333'
                        }
                    },
                    indicator: []
                },
                series: [{
                    type: 'radar',
                    areaStyle: {normal: {}},
                    data: []
                }]
            }
        };
    },
    mounted() {
        this.getData();
    },
    watch: {
        datasource: {
            deep: true,
            handler() {
                this.initChart();
            }
        }
    },
    methods: {
        getData() {
            this.$http.get('./chart/getradardata', {
                params: {}
            }).then(res => {
                this.datasource = res.data;
            });
        },
        initChart() {
            if (!this.datasource) {
                return;
            }

            this.chart.radar.indicator = this.datasource.indicator;
            this.chart.legend.data = this.datasource.series.map(item => item.name);
            this.chart.series[0].data = this.datasource.series;
            echarts.init(this.$refs.chart).setOption(this.chart);
        }
    }
};
</script>

<style lang="less" src="./index.less">

</style>
