1.基础用法
vue
<template>
<line-chart ref="chartRef" v-bind="chartOption"></line-chart>
</template>
<script setup>
import { ref, onMounted } from 'vue';
const chartRef = ref();
const xAxisData = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
const seriesData = [
{
yAxisIndex: 0,
data: [8, 30, 50, 82, 73, 84, 50]
},
{
yAxisIndex: 0,
data: [32, 94, 61, 11, 52, 68, 58]
},
{
yAxisIndex: 1,
data: [30, 44, 56, 24, 42, 58, 45]
}
];
const legendData = ['用水', '用电', '用工'];
const unit = ['吨', '千瓦时', '人'];
const yAxisName = ['左侧y轴', '右侧y轴'];
// 组合配置项
const chartOption = {
xAxisData,
seriesData,
legendData,
unit,
yAxisName,
showSplitLine: false
};
onMounted(() => chartRef.value.renderChart());
</script>
<style lang="scss" scoped>
.zrx-chart {
height: 340px;
background-color: white;
}
</style>2.显示数值与圆点
vue
<template>
<line-chart ref="chartRef" v-bind="chartOption"></line-chart>
</template>
<script setup>
import { ref, onMounted } from 'vue';
const chartRef = ref();
const xAxisData = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
const seriesData = [
{
yAxisIndex: 0,
data: [8, 30, 50, 82, 73, 84, 50]
},
{
yAxisIndex: 0,
data: [32, 94, 61, 11, 52, 68, 58]
}
];
const legendData = ['用水', '用电'];
const unit = ['吨', '千瓦时'];
const showLabel = true;
const showSymbol = true;
// 组合配置项
const chartOption = {
xAxisData,
seriesData,
legendData,
showLabel,
showSymbol,
unit
};
onMounted(() => chartRef.value.renderChart());
</script>
<style lang="scss" scoped>
.zrx-chart {
height: 340px;
background-color: white;
}
</style>3.颜色配置
vue
<template>
<line-chart ref="chartRef" v-bind="chartOption"></line-chart>
</template>
<script setup>
import { ref, onMounted } from 'vue';
const chartRef = ref();
const xAxisData = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
const seriesData = [
{
yAxisIndex: 0,
data: [8, 30, 50, 82, 73, 84, 50]
},
{
yAxisIndex: 0,
data: [32, 94, 61, 11, 52, 68, 58]
}
];
const legendData = ['用水', '用电'];
const unit = ['吨', '千瓦时'];
const color = ['green', 'red'];
const smooth = false;
// 组合配置项
const chartOption = {
xAxisData,
seriesData,
legendData,
unit,
color,
smooth
};
onMounted(() => chartRef.value.renderChart());
</script>
<style lang="scss" scoped>
.zrx-chart {
height: 340px;
background-color: white;
}
</style>属性
属性名
说明
类型
默认值
参考值
xAxisData
x 轴坐标
Array
[]
['周一', '周二', '周三', '周四', '周五', '周六', '周日']
seriesData
图表数据
Array
[]
[
{
yAxisIndex: 0,
data: [8, 30, 50, 82, 73, 84, 50]
},
{
yAxisIndex: 1,
data: [32, 94, 61, 11, 52, 68, 58]
}
]
{
yAxisIndex: 0,
data: [8, 30, 50, 82, 73, 84, 50]
},
{
yAxisIndex: 1,
data: [32, 94, 61, 11, 52, 68, 58]
}
]
legendData
legend 数据
Array
[]
['总能耗', '能耗照明']
smooth
是否平滑
Boolean, Number
true
false
showLabel
是否显示 label
Boolean
false
true
showSymbol
是否显示 symbol
Boolean
false
true
unit
单位
String, Array
[]
['kw/h', 'kg']
grid
上下左右边距
Object
({
top: 60,
right: 29,
bottom: 36,
left: 48
})
top: 60,
right: 29,
bottom: 36,
left: 48
})
{ top: 84, right: 18, bottom: 56, left: 56 }
yAxisName
y 轴名称
Array
['']
'亿元'
legendPosition
legend 定位
Object
({ top: 20, left: 16 })
{ top: 120, left: 316 }
tooltipNames
tooltip 名称数组
Array
[]
['名称A', '名称B']
color
预设颜色
Array
['#405FFE', '#1BBE8C', '#FFA433']
['#405FFE', '#1BBE8C', '#FFA433']
showLineArea
线条区域是否显示渐变色
Boolean
true
false
showSplitLine
是否显示分割线
Boolean
true
false
tooltipConfine
是否将 tooltip 框限制在图表的区域内
Boolean
true
false
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()