1.基础用法
自定义中心
vue
<template>
<dashboard-chart ref="chartRef" :value="66" :max="100">
<h4 style="font-size: 16px; color: red; font-weight: 600;">自定义中心</h4>
</dashboard-chart>
<dashboard-chart ref="chartRef2" :radius="48" :value="66" :startAngle="90" :endAngle="-270" color="#F0465A"></dashboard-chart>
<dashboard-chart ref="chartRef3" :radius="48" :value="66" :startAngle="90" :endAngle="-270" color="#1BBE8C"></dashboard-chart>
<dashboard-chart ref="chartRef4" :radius="48" :value="66" :startAngle="90" :endAngle="-270" color="#405FFE"></dashboard-chart>
</template>
<script setup>
import { ref, onMounted } from 'vue';
const chartRef = ref();
const chartRef2 = ref();
const chartRef3 = ref();
const chartRef4 = ref();
const value = 66;
const max = 100;
const chartOption = { value, max };
onMounted(() => {
chartRef.value.renderChart();
chartRef2.value.renderChart();
chartRef3.value.renderChart();
chartRef4.value.renderChart();
});
</script>
<style lang="scss" scoped>
.zrx-chart {
height: 240px;
width: 160px;
display: inline-block;
background-color: rgb(3, 43, 68);
&:nth-child(2) {
width: 240px;
}
}
</style>2.修改颜色
自定义中心
vue
<template>
<dashboard-chart ref="chartRef" v-bind="chartOption">
<h4 style="font-size: 16px; color: red; font-weight: 600;">自定义中心</h4>
</dashboard-chart>
</template>
<script setup>
import { ref, onMounted } from 'vue';
const chartRef = ref();
const value = 66;
const chartOption = {
value,
layerColor: 'rgba(255, 0, 0, 0.3)',
color: 'green'
};
onMounted(() => chartRef.value.renderChart());
</script>
<style lang="scss" scoped>
.zrx-chart {
width: 440px;
height: 240px;
background-color: rgb(3, 43, 68);
}
</style>3.设置角度
自定义中心
vue
<template>
<dashboard-chart ref="chartRef" v-bind="chartOption">
<h4 style="font-size: 16px; color: red; font-weight: 600;">自定义中心</h4>
</dashboard-chart>
</template>
<script setup>
import { ref, onMounted } from 'vue';
const chartRef = ref();
const value = 66;
const chartOption = {
value,
startAngle: 120,
endAngle: -120
};
onMounted(() => chartRef.value.renderChart());
</script>
<style lang="scss" scoped>
.zrx-chart {
width: 440px;
height: 240px;
background-color: rgb(3, 43, 68);
}
</style>4.宽度半径
自定义中心
vue
<template>
<dashboard-chart ref="chartRef" v-bind="chartOption">
<h4 style="font-size: 16px; color: red; font-weight: 600;">自定义中心</h4>
</dashboard-chart>
</template>
<script setup>
import { ref, onMounted } from 'vue';
const chartRef = ref();
const value = 66;
const chartOption = {
value,
barWidth: 30,
radius: 100
};
onMounted(() => chartRef.value.renderChart());
</script>
<style lang="scss" scoped>
.zrx-chart {
width: 440px;
height: 240px;
background-color: rgb(3, 43, 68);
}
</style>属性
属性名
说明
类型
默认值
参考值
max
最大值
Number
100
200
layerColor
底色
String
'#50697a'
'#aabbcc'
color
颜色
String
'#34d3ec'
'red'
startAngle
起始角度
Number
200
180
endAngle
终止角度
Number
-20
-40
value
数值
Number
0
60
barWidth
环形条宽度
Number
10
20
radius
半径
Number
95
80
scale
图表缩放比例
Number
1
2
beforeSetOption
万能方法,图表渲染之前执行
Function
null
function (option, chart) {
return '执行对 option 的修改,绑定自定义事件等'
}
return '执行对 option 的修改,绑定自定义事件等'
}
afterSetOption
万能方法,图表渲染之后执行
Function
null
function (option, chart) {
return '执行对 option 的修改,绑定自定义事件等'
}
return '执行对 option 的修改,绑定自定义事件等'
}
支持方法
方法名
说明
例子
renderChart
渲染图表
chartRef?.value?.renderChart()
clearChart
清除图表
chartRef?.value?.clearChart()