首页 > 其他分享 >4.折线图

4.折线图

时间:2023-07-06 16:34:51浏览次数:26  
标签:show color data var params 折线图 type

1.普通折线图

 

<template>
  <div>
    <div ref="chart1" class="chart"></div>
  </div>
</template>
<script>
import * as echarts from "echarts";
export default {
  data() {
    return {
      chartOption: {
        backgroundColor: "#03213D",
        color: ["#5090FF", "#01B3E4"],
        tooltip: {
          trigger: "axis",
          backgroundColor: "rgba(8,49,107,0.9)", //设置背景颜色
          borderColor: "rgba(8,49,107,0.9)", //设置边框颜色
          textStyle: {
            color: "white" //设置文字颜色
          },
          formatter: function(params) {
            // 颜色默认是:params[i].color。
            // 如果是渐变颜色需要改写成:params[i].color.colorStops[0].color
            var relVal = params[0].name;
            for (var i = 0, l = params.length; i < l; i++) {
              relVal +=
                '<br/><span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:' +
                params[i].color +
                '"></span>';
              relVal += params[i].seriesName + " : " + params[i].value + "%";
            }
            return relVal;
          }
        },
        dataZoom: [
          {
            type: "slider", //给x轴设置滚动条
            show: true, //false直接隐藏图形
            xAxisIndex: [0],
            bottom: 0,
            height: 10,
            showDetail: false,
            startValue: 0, //滚动条的起始位置
            endValue: 4 //滚动条的截止位置(按比例分割x轴长度)
          },
          {
            type: "inside", //设置鼠标滚轮缩放
            show: true,
            xAxisIndex: [0],
            startValue: 0,
            endValue: 9
          }
        ],
        grid: {
          left: "2%",
          right: "5%",
          bottom: "5%",
          top: "30px",
          containLabel: true
        },
        legend: {
          show: true,
          icon: "rect",
          orient: "horizontal",
          left: "right",
          itemWidth: 12,
          itemHeight: 12,
          // formatter: ["{a|{name}}"].join("%"),
          textStyle: {
            fontSize: 12,
            color: "#6A93B9",
            height: 8,
            rich: {
              a: {
                verticalAlign: "bottom"
              }
            }
          },
          data: ["一号窗口", "二号窗口"]
        },
        xAxis: {
          type: "category",
          axisLine: {
            lineStyle: {
              color: "#BDD8FB",
              fontSize: 12
            }
          },
          axisLabel: {
            // interval:0,
            color: "#BDD8FB",
            fontSize: 12,
            formatter: function(params) {
              var newParamsName = ""; //最终拼接成的字符串
              var paramsNameNumber = params.length; //实际标签的个数
              var provideNumber = 5; //每行能显示的字数
              var rowNumber = Math.ceil(paramsNameNumber / provideNumber); //换行的话,需要显示几行,向上取整
              /* 判断标签的个数是否大于规定的个数,如果大于,则进行换行处理;如果不大于,就返回原标签 */
              if (paramsNameNumber > provideNumber) {
                //等同于rowNumber>1
                for (var p = 0; p < rowNumber; p++) {
                  var temStr = ""; //表示每一次截取的字符串
                  var start = p * provideNumber; //开始截取的位置
                  var end = start + provideNumber; //结束截取的位置
                  //此处特殊处理最后一行的索引值
                  if (p == rowNumber - 1) {
                    temStr = params.substring(start, paramsNameNumber); //最后一次不换行
                  } else {
                    temStr = params.substring(start, end) + "
"; //每一次拼接字符串并换行
                  }
                  newParamsName += temStr; //最终拼成的字符串
                }
              } else {
                newParamsName = params; //将旧标签的值赋给新标签
              }
              return newParamsName; //将最终的字符串返回
            }
          },
          axisTick: {
            show: false
          },
          data: []
        },
        yAxis: {
          name: "单位:百分比", //y轴单位
          type: "value",
          // min: 0,
          // minInterval: 1,
          max: 100,
          interval: 25,
          nameTextStyle: {
            fontSize: 12,
            color: "#BDD8FB",
            align: "center"
          },
          splitLine: {
            lineStyle: {
              color: "rgba(255, 255, 255, 0.15)"
            }
          },
          splitArea: { show: false },
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          axisLabel: {
            fontSize: 12,
            fontFamily: "Bebas",
            color: "#BDD8FB",
            formatter: "{value}%" //y轴数值加%
          }
        },
        series: [
          {
            type: "line",
            smooth: true, // 是否曲线
            name: "一号窗口", // 图例对应类别
            data: [], // 纵坐标数据
            areaStyle: {
              color: {
                type: "linear",
                x: 0, //右
                y: 0, //下
                x2: 0, //左
                y2: 1, //上
                colorStops: [
                  {
                    offset: 0.1,
                    color: "#5090FF" // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "#1057E500" // 100% 处的颜色
                  }
                ]
              }
            }
          },
          {
            type: "line",
            smooth: true,
            name: "二号窗口",
            data: [],
            areaStyle: {
              color: {
                type: "linear",
                x: 0, //右
                y: 0, //下
                x2: 0, //左
                y2: 1, //上
                colorStops: [
                  {
                    offset: 0.1,
                    color: "#01B3E4" // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "#86DCF300" // 100% 处的颜色
                  }
                ]
              }
            }
          }
        ]
      },
    };
  },
  async mounted() {
    const chart = echarts.init(this.$refs.chart1);
    chart.setOption(this.chartOption);
    await this.fetchData();
  },
  methods: {
    async fetchData() {
      //获取接口数据
      let xData = ["计生", "劳保医保", "房屋租赁", "退役军人","公积金","智慧人设","业务大厅"];
      let series1 = [40, 60, 70, 20, 50, 70, 90];
      let series2 = [10, 40, 50, 60, 30, 80, 70];
      //将数据渲染到echarts图
        const chart = echarts.init(this.$refs.chart1);
        chart.setOption({
          xAxis: {
            data: xData
          },
          series: [{ data: series1 }, { data: series2 }]
        });
    }
  }
};
</script>
<style scoped lang="scss">
.chart {
  width: 100%;
  height: 300px;
}
</style>

 

2.柱状图与折线图

 

<template>
  <div>
    <div ref="chart1" class="chart"></div>
  </div>
</template>
<script>
import * as echarts from "echarts";
export default {
  data() {
    return {
      chartOption: {
        grid: {
          top: 40,
          right: 40,
          bottom: 0,
          left: 40,
          containLabel: true
        },
        legend: {
          data: [
            {
              name: "订单量"
            },
            {
              name: "时长"
            }
          ],
          icon: "rect",
          itemWidth: 13,
          itemHeight: 13,
          itemGap: 40,
          top: 0,
          right: 30,
          textStyle: {
            color: "rgba(0, 0, 0, 0.85)"
          }
        },
        xAxis: {
          data: [],
          axisLabel: {
            color: "rgba(0, 0, 0, 0.45)"
          },
          axisTick: {
            show: false
          },
          axisLine: {
            lineStyle: {
              color: "rgba(0, 0, 0, 0.15)",
              width: 0
            }
          }
        },
        yAxis: [
          {
            type: "value",
            splitNumber: 10,
            axisLabel: {
              color: "rgba(0, 0, 0, 0.45)"
            },
            axisTick: {
              show: false
            },
            axisLine: {
              show: false
            },
            splitLine: {
              lineStyle: {
                color: "rgba(0, 0, 0, 0.15)"
              }
            }
          },
          {
            type: "value",
            alignTicks: true,
            splitLine: {
              show: false
            },
            axisLabel: {
              color: "rgba(0, 0, 0, 0.45)"
            }
          }
        ],
        series: [
          {
            name: "订单量",
            yAxisIndex: 0,
            type: "bar",
            data: [],
            barMaxWidth: 15,
            itemStyle: {
              borderRadius: [20, 20, 0, 0],
              color: {
                type: "linear",
                x: 0,
                y: -0.2,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "#A7CEFF"
                  },
                  {
                    offset: 1,
                    color: "#5B8FF9"
                  }
                ]
              }
            },
            emphasis: {
              label: {
                show: true,
                position: "top",
                color: "#1890FF"
              }
            }
          },
          {
            name: "时长",
            yAxisIndex: 1,
            type: "line",
            data: [],
            symbol: "circle",
            symbolSize: 8,
            lineStyle: {
              color: "#FF8C09"
            },
            itemStyle: {
              color: "#FF8C09"
            },
            emphasis: {
              itemStyle: {
                borderWidth: 2,
                borderColor: "#fff"
              },
              label: {
                show: true,
                position: "top",
                color: "#FF8C09",
                align: "left",
                offset: [10, 5]
              }
            }
          }
        ]
      }
    };
  },
  async mounted() {
    const chart = echarts.init(this.$refs.chart1);
    chart.setOption(this.chartOption);
    await this.fetchData();
  },
  methods: {
    async fetchData() {
      //获取接口数据
      let xData = ["1月", "2月", "3月", "4月", "5月", "6月"];
      let series1 = [820, 720, 930, 820, 580, 490];
      let series2 = [0.62, 0.41, 0.41, 0.19, 0.03, 0.12];
      //将数据渲染到echarts图
      const chart = echarts.init(this.$refs.chart1);
      chart.setOption({
        xAxis: {
          data: xData
        },
        series: [{ data: series1 }, { data: series2 }]
      });
    }
  }
};
</script>
<style scoped lang="scss">
.chart {
  width: 100%;
  height: 200px;
}
</style>

 

标签:show,color,data,var,params,折线图,type
From: https://www.cnblogs.com/chenJieLing/p/17532545.html

相关文章

  • echarts,时间轴折线图,tooltip相关
    其中,data数组是通过echarts工具由表格直接转换得到:https://echarts.apache.org/zh/spreadsheet.html第一部分:datadata中的长串是由表格得到,由日期转为的时间戳形式,比如‘1636905600000’,是excel中的【2021/11/150:00:00】通过公示【=((C3-70*365-19)*86400-8*3600)*1000】得到1......
  • R语言动态可视化:制作历史全球平均温度的累积动态折线图动画gif视频图|附代码数据
    全文链接:http://tecdat.cn/?p=9766原文出处:拓端数据部落公众号最近我们被客户要求撰写关于动态可视化的研究报告,包括一些图形和统计输出。 在某些情况下,你可能希望通过在每帧中添加数据并保留先前添加的数据来进行动画处理。现在,我们将通过制作点线图的动画来探索。以下是制......
  • echart折线图点击事件包括任意位置
    echart折线图点击事件包括任意位置一、常规点击事件在echarts中可以使用on为图形添加点击事件,但是这种方式添加的点击事件,只有点击在图形元素上才会触发事件处理函数。myChart.on('click',params=>{//可以设置点击的类型与响应的系列if(params.seriesType==='line'){......
  • Python+matplotlib绘制动态折线图
    问题描述:动态绘制折线图。参考代码:运行效果:公众号“Python小屋”......
  • Echarts 折线图y轴标签值太长时显示不全的解决办法
    option={...yAxis:{type:'value',name:'营业额(元)',axisTick:{inside:true},scale:true,axisLabel:{margin:2,formatter:function(va......
  • echarts的折线图的鼠标滚轮移动不缩放
    dataZoom:[{type:'slider',maxValueSpan:5,//显示数据的条数(默认显示10个)show:true,yAxisIndex:[0],left:'93%',//滑动条位置start:100,//默认为0end:70,//默认为100orient:"vertical",filterMode:'empty',zoomLock:true,},{type:'inside......
  • echarts折线图颜色渐变设置
    constcolor1="rgb(229,53,59,0.05)"constcolor2="rgb(229,53,59,0)"series:[{data:[12,30,60,80,100,60,130,12,30,60,80,100,60,130],type:'line',......
  • 折线图highcharts.js -纯js图表库
    查看演示功能强大、开源、美观、图表丰富、兼容绝大多数浏览器的纯js图表库ps:使用highcharts怎么去掉图表上那个官网标识链接credits:{enabled:false}......
  • 折线图 最大值显示白点,默认显示tooltip框框,自定义tooltip
    效果图: 代码如下:(直接放整个vue文件了,省事)<template><div><divstyle="width:406px;height:220px"id="zz_r_two1"></div><divclass="xsTitle"><divclass="fang"></div>......
  • 双Y轴曲线阴影 折线图
    效果如下 代码:<template><divstyle="width:406px;height:190px"id="it_r_two"></div></template><script>exportdefault{name:"it_r_two",data(){return{};},mounted(){......