Echarts初学经验

每次接触新知识的时候,总会有那么死去活来的两天。不管多难的东西,只要自己不放弃自己,前途一片光明。

以下介绍Echarts一些基本的配置项

一、标题组件title

  • 主表题样式设置textStyle
    1、color:主表题文字颜色
    2、fontStyle:主标题文字字体的风格可选'normal''italic''oblique'
    3、fontWeight:主标题文字字体的粗细

文字样式方面,上述属性,基本通用


title: {
        text: '主表题 ',
        subtext: '  副标题',
        left: '控制标题距离左边距离',
        top: '控制标题右边距离',
        textStyle: {//主表题样式设置
          textAlign: 'center',
          color: '#505D6F',
          fontSize: 15,
        },
        subtextStyle: {//副标题样式设置
          textAlign: 'center',
          fontSize: 15,
        },
      },

image.png

二、图例组件legend

  • 图例的数据数组data
    1、name:图例项的名称,应等于series中的某个name值
    2、icon:ECharts 提供的标记类型包括 'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow', 'none'
    3、textStyle:图例项的文本样式。
legend: {
        orient: 'horizontal',//图例水平数值排列
        itemGap: 25,//图例每项之间的间隔
        top: 0,//top,left,等控制图例们的位置
        textStyle: {//图例文字样式
          color: '#666666',
          fontSize: 15,
        },
        data: [
            {
              name:'一',
              icon:'circle',//图例样式
            },
            {
                name:'二',
              icon:'circle',
            },
            {
                name:'三',
              icon:'circle',
            },
            {
                name:'四',
              icon:'',
            }
            ],
      },

image.png

三、图表网格绘制grid(控制位置的)

 grid: {
        left: '3%',
        right: '4%',
        bottom: '0%',
        top: '15%',
        containLabel: true, //区域是否包含刻度图标
      },

四、直角坐标系grid中的x轴xAxis

  • 坐标轴线相关设置axisLine
    1、show:是否显示
    2、lineStyle:相关线条样式设置

  • 坐标刻度标签相关设置axisLabel

  • 坐标轴刻度相关设置axisTick
    1、show:是否显示
    2、lineStyle:相关线条样式设置

  • 类目数据data
    1、单个类目名称value
    2、类目标签的文字样式textStyle

xAxis: [
        {
          type: 'category',
          axisLine: {
            show: true,//坐标轴线是否显示
            lineStyle: {//坐标轴线样式
              color: '#888888',
              width: 2,
            },
          },
          axisLabel: {//坐标刻度标签设置
            show: true,
            color: '#888888',
          },
          axisTick: {//坐标轴刻度设置
            show: true,
            alignWithLabel: true, //刻度对齐方式
            lineStyle: {
              color: '#888888',
              width: 2,
            },
          },
          data: [
            '1日',
            '3日',
            '5日',
            '7日',
            '9日',
            '11日',
            '13日',
            '15日',
            '17日',
            '19日',
            '21日',
            '23日',
            '25日',
            '27日',
            '29日',
          ],
        },
      ],

image.png

五、直角坐标系grid中的y轴yAxis

  • 直角坐标系 grid 中的 y 轴,一般情况下单个 grid 组件最多只能放左右两个 y 轴,多于两个 y 轴需要通过配置 offset 属性防止同个位置多个 Y 轴的重叠。

其中属性详见官网


yAxis: [
        {
          type: 'value',
          name: '左侧坐标轴',
          axisLine: {
            show: true,
            lineStyle: {
              color: '#888888',
              width: 1,
            },
          },
          axisLabel: {
            show: true,
            color: '#888888',
          },
          axisTick: {
            show: true,
            lineStyle: {
              color: '#888888',
              width: 2,
            },
          },
          splitLine: {//横向分割线
            lineStyle: {
              type: 'solid',
              color: '#888888',
            },
          },
        },
        {
          type: 'value',
          name: '右侧坐标轴',
          min: 0,
          max: 100,
          interval: 20,
          axisLine: {
            show: true,
            lineStyle: {
              color: '#888888',
              width: 1,
            },
          },
          axisLabel: {
            show: true,
            color: '#888888',
          },
          axisTick: {
            show: true,
            lineStyle: {
              color: '#888888',
              width: 2,
            },
          },
          splitLine: {
            lineStyle: {
              type: 'solid',
              color: '#ccc',
            },
          }, //设置横向分割线颜色
        },
      ],

image.png

六、系列列表series

  • type:可选line(折线图),pie(饼图),bar(柱状图)等等
  • name:legend中的name与此处相同时显示图例
  • stack:数据堆叠,同个类目轴上系列配置相同的stack值可以堆叠放置
  • itemStyle:设置图形样式
series: [
        {
          name: '一',
          type: 'bar',
          stack: '广告',
          data: [40, 70, 100, 100, 130, 150, 170, 202, 240, 250, 206, 208, 200, 170],
          itemStyle: {
            color: '#00f',
          },
          barWidth: 22,
        },
        {
          name: '二',
          type: 'bar',
          stack: '广告',
          data: [40, 50, 60, 80, 100, 130, 140, 150, 160, 160, 170, 190, 100, 150, 160],
          itemStyle: {
            normal: {
              color: '#0f0',
            },
          },
          barWidth: 22,
        },
        {
          name: '三',
          type: 'bar',
          stack: '广告',
          data: [40, 50, 60, 80, 100, 100, 80, 70, 50, 30, 30, 60, 90, 80, 60],
          itemStyle: {
            normal: {
              barBorderRadius: [40, 40, 0, 0],
              color: '#f00',
            },
          },
          barWidth: 22,
        },
        {
          name: '四',
          type: 'line',
          color: '#9E86FF',
          yAxisIndex: 0,
          data: [150, 119, 213, 314, 215, 318, 425, 228, 133, 434, 335, 340, 150, 170, 180],
          itemStyle: {
            normal: {
              lineStyle: {
                width: 4,
                shadowColor: '#9E86FF',
                shadowBlur: 10,
                shadowOffsetY: 0,
              },
            },
          },
          smooth: true,
          symbol: '',
        },
      ],

image.png

本文主要介绍了Echarts的基本用法以及大概模板,想要熟练掌握还需要多多练习,想搞更多花样还要自己阅读官方的配置项手册更多花样将在其它文章中介绍。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 原文链接 https://blog.csdn.net/she_lover/article/details/5144...
    丶温瞳阅读 6,895评论 0 0
  • [echarts属性的设置(完整大全)]转自https://www.cnblogs.com/benmumu/p/8...
    雅雅的前端工作学习阅读 321评论 0 0
  • 这篇文章主要讲述Echarts设置字体和线条的颜色相关操作笔记,希望文章对你有所帮助,主要是自己的在线笔记吧。我在...
    蓝色梦想家阅读 10,094评论 1 1
  • 在vue使用echarts echarts是什么 ecahrts 是一个高度可定制化的图表库 如何使用echart...
    小将和硝子阅读 2,210评论 0 3
  • 参与为我国冬奥代表团提供精细化赛场气象保障服务的中央气象台副首席预报员董全告诉记者,韩国平昌地区位于亚洲东...
    浮图塔z阅读 1,144评论 0 0