折线图演示
参考配置
基础折线图
html
<template>
<view class="container">
<t-xcharts
ref="chart"
:option="chartOption"
></t-xcharts>
</view>
</template>
<script setup>
import { ref } from 'vue';
const chartOption = ref({
type: 'line',
animation: true,
dataLabel: true,
xAxis: {
disableGrid: true
},
yAxis: {
data: [{
min: 0,
max: 100
}]
},
series: [{
name: '访问量',
data: [35, 20, 25, 45, 37, 43, 34],
color: '#2979ff'
}],
categories: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
});
</script>平滑折线图
html
<template>
<view class="container">
<t-xcharts
ref="chart"
:option="chartOption"
></t-xcharts>
</view>
</template>
<script setup>
import { ref } from 'vue';
const chartOption = ref({
type: 'line',
animation: true,
dataLabel: true,
smooth: true,
xAxis: {
disableGrid: true
},
yAxis: {
data: [{
min: 0,
max: 100
}]
},
series: [{
name: '访问量',
data: [35, 20, 25, 45, 37, 43, 34],
color: '#2979ff'
}],
categories: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
});
</script>多系列折线图
html
<template>
<view class="container">
<t-xcharts
ref="chart"
:option="chartOption"
></t-xcharts>
</view>
</template>
<script setup>
import { ref } from 'vue';
const chartOption = ref({
type: 'line',
animation: true,
dataLabel: true,
smooth: true,
xAxis: {
disableGrid: true
},
yAxis: {
data: [{
min: 0,
max: 100
}]
},
series: [
{
name: '访问量',
data: [35, 20, 25, 45, 37, 43, 34],
color: '#2979ff'
},
{
name: '注册量',
data: [25, 30, 35, 27, 33, 44, 40],
color: '#19be6b'
}
],
categories: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
});
</script>配置说明
type
图表类型,设置为 'line' 表示折线图。
series
数据系列配置:
name: 系列名称data: 数据数组color: 线条颜色
categories
X轴分类标签数组。
smooth
是否平滑曲线,设置为 true 启用平滑效果。
dataLabel
是否显示数据标签。
animation
是否启用动画效果。