<template>
<div
class="eachar02"
style="height:100%"
>
<div
id="left_bottom"
style="width: 100%;height: 100%"
></div>
</div>
</template>
<script>
import * as echarts from "echarts";
import { gzAPI } from "@/API/gzapi.js";
import { PublicFunction } from "@/utils/vuePublic.js";
export default {
created() {},
mounted() {
this.init();
},
data() {
return {
xdata: [],
ydata: [],
dataTwo: [],
};
},
methods: {
init() {
let _this = this;
// 随机数
let arr = PublicFunction.random(10, 20, 14);
let arr1 = PublicFunction.random(15, 100, 14);
//获取当前日期以及前7天的值
let arrdata = PublicFunction.sevenDay(14);
console.log("当前日期以及6天的日期", arrdata);
// console.log("随机数", arr);
let res = {
code: "200",
msg: "查询成功",
xdata: arrdata,
ydata: [
{
ydataID: 1,
ydataName: "测试1",
ydataChild: arr,
},
{
ydataID: 2,
ydataName: "测试2",
ydataChild: arr1,
},
],
};
_this.xdata = res.xdata;
_this.ydata = res.ydata;
this.initData();
},
initData() {
var chartDom = document.getElementById("left_bottom");
var myChart = echarts.init(chartDom);
var option;
option = {
//你的代码
// title: [
// {
// text: "数据标题展示",
// textStyle: {
// fontSize: 20,
// color: "#fff",
// },
// left: "50%",
// top:"2%",
// },],
// backgroundColor: "#000",
grid: {
//位置
left: "5%",
right: "3%",
top: "20%",
bottom: "0%",
containLabel: true, //这常用于『防止标签溢出』的场景
},
// 提示框组件
tooltip: {
trigger: "axis",//坐标轴触发;item 数据项图形触发;none不触发
axisPointer: { //刻度线
type: "cross",//十字型,shadow 阴影型;line直线型
crossStyle: {
color: "#999", //线的颜色
},
lineStyle: {
type: "dashed", //线的类型
},
},
},
xAxis: [
{
type: "category",
axisLabel: {// x轴刻度线上的样式
color: "#fff",
margin: 14,
textStyle: {
fontSize: 10,
},
interval: 0, //x轴刻度线之间的间隔
rotate: 0, //x轴倾斜
},
axisLine: {
show: true,
lineStyle: {
color: "#397cbc",
},
},
axisTick: {
show: false,
},
splitLine: {
show: false,
lineStyle: {
color: "#195384",
},
},
data: this.xdata,
},
],
yAxis: [
{
type: "value",
name: "保障次数",
nameTextStyle: {
color: "#82A9EF",
},
min: 0,
max: 100, //最大值
axisLabel: {
formatter: "{value}",
textStyle: {
color: "#82A9EF",
fontSize: 14,
},
},
axisLine: {
show: false,
lineStyle: {
color: "#27b4c2",
},
},
axisTick: {
show: false,
},
splitLine: {
show: true,
lineStyle: {
color: "#11366e",
},
},
},
],
dataZoom: [
//平移:在坐标系中滑动拖拽进行数据区域平移。
{
show: true,
realtime: true,
start: 0,
end: 20,
height: 10,
bottom: 10,
},
],
series: [
{
name: "保障次数",
type: "line",
stack: "总量",
symbol: "circle",
symbolSize: 4,
itemStyle: {
normal: {
color: "#FFFF00",
lineStyle: {
color: "#FFFF00",
width: 1,
},
areaStyle: {
//color: '#94C9EC'
color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
{
offset: 0,
color: "RGBA(255, 255, 0, 0.2)",
},
{
offset: 1,
color: "RGBA(255, 255, 0, 0.3)",
},
]),
},
},
},
markPoint: {
itemStyle: {
normal: {
color: "red",
},
},
},
data: this.ydata[0].ydataChild,
},
{
name: "市中",
type: "line",
stack: "总量",
symbol: "circle",
symbolSize: 4,
itemStyle: {
normal: {
color: "#F64D5F",
lineStyle: {
color: "#F64D5F",
width: 1,
},
areaStyle: {
//color: '#94C9EC'
color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
{
offset: 0,
color: "RGBA(246, 77, 95, 0.2)",
},
{
offset: 1,
color: "RGBA(246, 77, 95, 0.3)",
},
]),
},
},
},
data: this.ydata[1].ydataChild,
},
],
};
option && myChart.setOption(option);
},
},
};
</script>
<style>
</style>
echars 折线图
最新推荐文章于 2024-07-22 08:55:10 发布