因为echart图高度比较小,所以折线图中的数字差别不是很大的时候,看着像一条直线,当把高度改到500px时,才能明显看出折线图的起伏,请问该怎么设置呢?
<template>
<div>
<div id="chart-panel" style="height: 50px; width: 100%;"></div>
</div>
</template>
<script>
var echarts = require("echarts");
let dataTemp = [
{ date: "2024-10-31", value: 3, rate: 11.1 },
{ date: "2024-11-01", value: 14, rate: 14.1 },
{ date: "2024-11-02", value: 21, rate: 15.1 },
{ date: "2024-11-03", value: 24, rate: 16.1 },
{ date: "2024-11-04", value: 18, rate: 21.1 },
{ date: "2024-11-05", value: 20, rate: 31.1 },
{ date: "2024-11-06", value: 24, rate: 25.5 },
];
export default {
name: "",
props: {
},
mounted() {
var dom = document.getElementById("chart-panel");
var myChart = echarts.init(dom);
var option;
var app = {};
option = {
// backgroundColor: "#05224d",
title: {
// text: '单位:(万元)',
textStyle: {
// color: "rgba(131, 162, 192, 1)",
fontSize: 12,
},
top: "4%",
left: "2%",
},
tooltip: {
trigger: "axis",
},
legend: {
data: ["数量"],
icon: "rich",
show: false,
itemWidth: 14,
itemHeight: 14,
textStyle: {
color: "#C6D1DB",
fontSize: "14px",
},
top: 8,
right: 10,
itemGap: 34,
},
grid: {
left: "0",
right: "0",
bottom: "0",
top: "0",
containLabel: true,
},
formatter: function(params) {
let param = params.length > 0 ? params[0] : {};
var res = `
<div>
<span>数量:${param.data.value}</span>
</div>
<div>
<span>比例:${param.data.rate}%</span>
</div>
`;
return param.name + res;
},
xAxis: {
data: dataTemp.map(s => s.date),
type: "category",
boundaryGap: false,
axisLine: {
show: false,
},
axisTick: {
show: false,
},
axisLabel: {
interval: 0,
color: "rgba(255, 255, 255, 0.3)",
fontSize: 12,
padding: [10, 0, 0, 0],
},
},
yAxis: {
type: "value",
boundaryGap: false,
min: 0,
max: 30,
axisTick: {
show: false, //刻度线
},
axisLine: {
show: false, //隐藏y轴
},
axisLabel: {
show: false, //隐藏刻度值
},
splitLine: {
lineStyle: {
color: "rgba(255, 255, 255, 0.12)",
type: "dashed",
},
},
},
series: [
{
name: "数量",
type: "line",
data: dataTemp,
smooth: true,
color: "rgba(38, 127, 235, 1)",
lineStyle: {
width: 2,
},
showSymbol: false,
areaStyle: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: "rgba(38, 127, 235, 0.15)",
},
{
offset: 1,
color: "rgba(38, 127, 235, 0)",
},
],
false
),
shadowColor: "rgba(0, 0, 0, 0.1)",
shadowBlur: 10,
},
symbol: "circle",
symbolSize: 4,
},
],
};
if (option && typeof option === "object") {
myChart.setOption(option);
}
},
data() {
return {};
},
};
</script>
找到问题了:
grid需要修改为:containLabel: false
因为echart图高度比较小,所以折线图中的数字差别不是很大的时候,看着像一条直线,当把高度改到500px时,才能明显看出折线图的起伏,请问该怎么设置呢?
问题找到了:
grid需要修改为:
containLabel: false