| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <template>
- <div class="unsafe-types-chart">
- <div class="chart-container" ref="typesChart"></div>
- <div class="types-list">
- <div v-for="(item, index) in chartsData.types" :key="index" class="list-item">
- <div class="item-name">{{ item.name }}</div>
- <div class="item-value">{{ item.value }}</div>
- </div>
- </div>
- </div>
- </template>
- <script>
- import * as echarts from 'echarts'
- export default {
- name: 'UnsafeTypesChart',
- props: {
- chartsData: {
- type: Object,
- default: () => ({
- types: [
- { name: '一类', value: 56 },
- { name: '二类', value: 57 },
- { name: '三类', value: 56 },
- { name: '四类', value: 55 },
- { name: '五类', value: 55 }
- ]
- })
- }
- },
- data() {
- return {
- chart: null
- }
- },
- mounted() {
- this.$nextTick(() => {
- this.initChart()
- })
- },
- watch: {
- chartsData: {
- deep: true,
- handler() {
- this.$nextTick(() => {
- if (this.chart) this.chart.dispose()
- this.initChart()
- })
- }
- }
- },
- methods: {
- initChart() {
- if (!this.$refs.typesChart) return
- this.chart = echarts.init(this.$refs.typesChart)
- const option = {
- responsive: true,
- maintainAspectRatio: false,
- tooltip: {
- trigger: 'item',
- formatter: '{b}: {c} ({d}%)'
- },
- series: [{
- type: 'pie',
- radius: ['50%', '70%'],
- data: this.chartsData.types.map(item => ({
- name: item.name,
- value: item.value
- })),
- itemStyle: {
- color: function(params) {
- const colors = ['#A78BFA', '#6366F1', '#8B5CF6', '#7C3AED', '#6D28D9']
- return colors[params.dataIndex]
- }
- },
- label: {
- show: true,
- color: '#333',
- fontSize: 10,
- formatter: '{b}\n{d}%'
- }
- }]
- }
- this.chart.setOption(option)
- }
- },
- beforeDestroy() {
- if (this.chart) this.chart.dispose()
- }
- }
- </script>
- <style lang="scss" scoped>
- .unsafe-types-chart {
- .chart-container {
- height: 220rpx;
- }
- .types-list {
- margin-top: 16rpx;
- }
- .list-item {
- display: flex;
- justify-content: space-between;
- font-size: 24rpx;
- padding: 8rpx 0;
- .item-name {
- color: #666;
- }
- .item-value {
- color: #333;
- }
- }
- }
- </style>
|