使用:echarts使用

Echarts 是一种常用的图表。 

帅帅哥常的操作笔记分解

颜色: color: ['#1890FF', '#00C6C4’]

 

标题大小、颜色:

        title : {

                text:'流量统计与转化',

                x: 'center',

                y: '70%',

                textStyle:{

                    fontSize: 14,

                    color: '#000',

                    fontWeight: 'normal',

                },

        }

 

图表的内边距:可理解为padding

        grid: {

              left: '2%',

              right: '2%',

              bottom: '6%',

              containLabel: true

         }

 

 

 

图表标题: 

         legend: {

              居中

              orient: ‘horizon tal',  // 'horizontal/vertical’ ,

              x: 'center’, 

             表标题标志类型(圆)

              icon: 'circle’,

              内边距

              padding: [20, 0, 0, 0],

              表标题圆宽高

              itemWidth: 40,

              itemHeight: 10,

              表标题间距

              itemGap: 40,

          },

 

X、Y 轴背景线的样式:

        xAxis : {

              splitLine:{

                  lineStyle: {

                      type: 'dashed',

                      color: '#E8E8E8',

                  }

              }

        }

        

 

X 轴文字过长处理方法:

     xAxis : {

         1、倾斜

         axisLabel: {

               interval: 0,               

               rotate: 40,

          }

 

          2、垂直

           axisLabel: {

               formatter:function(value) {

                   return value.split("").join("\n");

               }

           }

 

           3、省略号

           axisLabel: {

               formatter: function (value, index) {

                      // 1 2 这些你自定义就行

                      var v = value.substring(0, 3) + '...'

                      return value.length > 2 ? v : value

              }

           }

 

      }

 

注)

1、interval

    坐标轴刻度标签的显示间隔(类目轴中有效),默认会采用标签不重叠的方式显示(默认会将部分文字显示不全)

 

   可以设置为0强制显示所有标签,如果设置为1,表示隔一个标签显示一个标签,如果为3,表示隔3个标签显示一个标签,以此类推。

2、rotate

  标签倾斜的角度,在类目轴的类目标签显示不全时可以通过旋转防止标签重叠,旋转的角度是-90到90度。

 

倾斜:

 

垂直:

 

省略号:

 

X 、Y 轴数据转换 

   xAxis: {

          X轴坐标轴两端空白

           boundaryGap : false

 

           X 、Y轴网络线去除

           splitLine:{ show: false }

 

          X 、Y 轴网络区域去除

           splitArea : {show : false}

 

          X 、Y 轴线颜色、宽度

          axisLine: {

               lineStyle: {

                   color: ‘red', 

                   width: 1, 

               }

           }

 

          X 、Y 轴线分隔线、颜色

           axisTick: {

               show:false,

               lineStyle: {

                   color: ‘#000', 

                   width: 1, 

               }

           }

 

          X 、Y 轴文字颜色

          axisLabel: {

               textStyle: {

                  color: '#000'

               },

          }

    }

 

图表边框线去除

      grid: {

           show:'true',

           borderWidth:'0'

      }

 

鼠标放上去有阴影

     tooltip : {

         trigger: 'axis',

               axisPointer: {

                    type: ‘shadow'

               }

         },

     }

 

 

 

修改前:

 

修改后: X、Y 轴数据转换

 

 

图表边框线去除:(边框线存在原力如下:鼠标放上去有阴影)

 

鼠标放上去有阴影:

 

Y 轴的数据转换:

      1、小数转成百分比

         yAxis: {

            type: 'value',

                    axisLabel:{

                         // formatter:'{value}%'

                        formatter:function(value) {

                            return value*100 + '%';

                        }

                    }

         },

 

      2、鼠标放上去的地方也要转成百分比

        tooltip: {

                trigger: 'axis',

                axisPointer: {

                        type: 'shadow'

                },

                formatter:function(c) {

            return (c[0].value)*100 + '%';

          }

        },

 

注)Echarts 中 如果要写js,都在 formatter 这个函数里面写。

修改前:

 

修改后:

1、小数转成百分比

 

2、鼠标放上去的地方也要转成百分比

 

 

 

 

ECharts 基础引入方法

 

Js 中使用方法

参考官方文档,直接引用

参考官方文档,直接引用

react 中使用方法 

 

 

 

// 引入 ECharts 主模块

import ReactEcharts from 'echarts-for-react';

// 引入柱状图

import 'echarts/lib/chart/bar';

// 引入提示框和标题组件

import echarts from 'echarts/lib/echarts';

import 'echarts/lib/component/tooltip’;

 

getOptionLineOne = ( ) =>({  //do something })

 

<ReactEcharts 

      showLoading={this.props.loading} 

      loadingOption={{

         text: '数据正在努力 加载…',

         effect:'bubble’,

     }} 

      option={this.getOptionLineOne()} 

     style={{ height: 328 }}  

/>

 

vue 中使用方法 

 

<script>

  import echarts from 'echarts/lib/echarts';

  // 引入柱状图

  import 'echarts/lib/chart/pie';

  import 'echarts/lib/component/title';

  import 'echarts/lib/component/legend';

  import 'echarts/lib/component/tooltip';

 

<template>

    <div style="width: 300px;height:145px;"></div>

</template>

 

  export default {

    mounted(){

      this.myChart = echarts.init(document.getElementById('visitorpie'));

      this.initData();

    },

    props: ['pieData'],

    methods: {

      initData(){

        const option = {

            // do something

        };

        this.myChart.setOption(option);

      }

    },

    watch: {

      pieData: function (){

        this.initData()

      }

    }

  }

</script>

 

 

 

 

 

 

 

 

 

 

 

    

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
错误"ReferenceError: echarts is not defined"表示在代码尝试使用echarts库时出现了问题。根据引用和引用的描述,可能是echarts库没有被正确引入。这个错误通常发生在以下几种情况下: 1. 没有正确引入echarts库:请确保在代码正确引入了echarts库,可以通过在HTML文件添加<script>标签引入echarts库的CDN链接或者本地文件路径来解决这个问题。 2. echarts库加载顺序错误:如果echarts库被其他脚本提前加载或者加载顺序有误,也会导致该错误。确保echarts库在使用之前已经被正确加载。 3. echarts库版本不兼容:某些情况下,可能是因为echarts库的版本不兼容导致的错误。请检查代码使用echarts版本是否与文档或示例代码一致。 4. 脚本位置错误:如果代码的脚本位置不正确,可能导致echarts库未能被正确加载。请确保脚本位置正确并且在需要使用echarts的地方之前加载。 综上所述,要解决"ReferenceError: echarts is not defined"错误,您可以按照以下步骤操作: 1. 确保正确引入echarts库,并检查引入方式和路径是否正确。 2. 检查echarts库的加载顺序是否正确,确保在使用echarts之前已经加载。 3. 确认使用echarts版本与代码兼容。 4. 检查代码脚本的位置,确保在需要使用echarts的地方之前加载。 通过以上步骤,您应该能够解决"ReferenceError: echarts is not defined"错误。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Uncaught ReferenceError: echarts is not defined](https://blog.csdn.net/ze1024/article/details/115691923)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [记录使用echart遇到的错误](https://blog.csdn.net/maple_leaf_red/article/details/107283148)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值