vehicle-monitor/src/views/data-analyse/charts/left-brand.ts

60 lines
1.4 KiB
TypeScript
Raw Normal View History

import 'echarts/lib/component/dataZoom';
import type { Ref } from 'vue';
import echarts from '@/plugins/echarts';
import { debounceChart } from '@/utils/chart';
let myChart = null;
const option = {
tooltip: { trigger: 'item' },
2025-05-24 13:52:02 +08:00
legend: { top: 'bottom', textStyle: { color: '#fff' } },
series: [
{
name: '品牌占比',
type: 'pie',
radius: [25, 100],
center: ['50%', '45%'],
roseType: 'area',
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)',
},
},
2025-05-24 13:52:02 +08:00
label: { formatter: '{b}: {c}%', color: '#fff' },
data: [
{ value: 10.89, name: '品牌A' },
{ value: 30.89, name: '品牌B' },
{ value: 38.38, name: '品牌C' },
{ value: 27.47, name: '品牌D' },
{ value: 29.79, name: '品牌E' },
{ value: 50, name: '品牌F' },
{ value: 50, name: '品牌G' },
{ value: 39.72, name: '品牌H' },
],
},
],
};
/** 渲染图表 */
export const renderEcharts = (element: Ref<HTMLDivElement>) => {
myChart = echarts.init(element.value, null, {
renderer: 'canvas',
devicePixelRatio: window.devicePixelRatio,
});
debounceChart(myChart);
myChart.setOption(option);
};
/** 更新图表数据 */
2025-05-24 13:52:02 +08:00
export const updateChart = (data: any) => {
const series = myChart.getOption().series;
2025-05-24 13:52:02 +08:00
series[0].data = data;
myChart.setOption({ series });
};