echarts icon indicating copy to clipboard operation
echarts copied to clipboard

toolBox自定义button,icon能够用图片以外的方式自定义吗?

Open jjackychen opened this issue 10 years ago • 7 comments

问题简述 (One-line summary)

toolBox自定义button,icon能够用图片以外的方式自定义吗? 如果用图片作icon效果比较难看。

版本及环境 (Version & Environment)

  • ECharts 版本 (ECharts version):V3.1.10
  • 浏览器类型和版本 (Browser version):
  • 操作系统类型和版本 (OS Version):

重现步骤 (Steps to reproduce)

期望结果 (Expected behaviour)

像原有的button icon一样的样式,我自定义文字。如:1H,2H,3H 等

可能哪里有问题 (What went wrong)

ECharts配置项 (ECharts option)

      option = {
            title: {
                text: '温度(°C)',
                x: 'center'
            },
        legend: {
            show: true,
            right: '0',
            data: [
                '温度1','温度2','温度3'
            ]
        },
        tooltip: {
            trigger: 'axis',
            formatter: function(params) {
                var result = "";
                for (var i = 0; i < params.length; i++) {
                    var p = params[i];
                    var seriesName = p.seriesName;
                    if (typeof(p.value) == "undefined") {
                        result += seriesName + ',  <br />';
                    } else {
                        var date = new Date(p.value[0]);
                        var value = p.value;
                        result += seriesName.substring(0,seriesName.length - 2) + ', ' + date.toLocaleString() + ' ,' + p.value[1] + '<br />';
                    }
                }
                return result;
            }
        },
 toolbox:{
                        show : true,  
                        itemSize:20,
                        feature : {  
                            myTool: {
                                show : true,
                                title : '1H',
                                icon : 'image://images/1H.jpg', 
                                onclick : function (){
                                     range = '1h';
                                     setRange(range, startxAxis, lastxAxis);
                                }
                            },
                            myTool2 : {
                                show : true,
                                title : '2H',
                                icon : 'image://images/2H.jpg', 
                                onclick : function (){
                                    range = '2h';
                                    setRange(range, startxAxis, lastxAxis);
                                }
                            },
                            myTool3 : {
                                show : true,
                                title : '3H',
                                icon : 'image://images/3H.jpg', 
                                onclick : function (){
                                    range = '3h';
                                    setRange(range, startxAxis, lastxAxis);
                                }
                            },
                            myTool4 : {
                                show : dayFlag,
                                title : '1D',
                                icon : 'image://images/1D.jpg', 
                                onclick : function (){
                                    range = '1d';
                                    setRange(range, startxAxis, lastxAxis);
                                }
                            },
                            myTool5 : {
                                show : true,
                                title : 'All',
                                icon : 'image://images/ALL.jpg', 
                                onclick : function (){
                                    range = 'ALL';
                                    setRange(range, startxAxis, lastxAxis);
                                }
                            }
                        } ,
                        left:'left' 
                    },
        xAxis: [{
            type: 'time'
        }],
        yAxis: [{
            type: 'value',
            axisLabel: {
                formatter: '{value} °C'
            }
        }],
        grid: {
            left: '6%',
            right: '9%',
            bottom: '9%',
            containLabel: true
        },
        dataZoom: [{
            type: 'inside',
            orient: 'horizontal',
          startValue:'2016/05/30 00:31:01',
          endValue:'2016/05/30 00:34:00'
        },{
            type: 'slider',
            orient: 'horizontal'

        },{
            type: 'inside',
            orient: 'vertical'
        },{
            type: 'slider',
            orient: 'vertical'
        }],
        series: [
            {
              name: '温度1',
              type: 'line',
              showSymbol: false,
              hoverAnimation: false,
              sampling: 'max',
              markLine: {
                symbol: ['none', 'none'],
                data: [{
                  name: '上限',
                  type: 'max',
                  yAxis: 31.0,
                  lineStyle: {
                    normal: {
                      color: '#FF3030'
                    }
                  },
                  label: {
                    normal: {
                      formatter: '{c}{b}'
                    }
                  }
                }, {
                  name: '下限',
                  type: 'min',
                  yAxis: 29.0,
                  lineStyle: {
                    normal: {
                      color: '#FF3030'
                    }
                  },
                  label: {
                    normal: {
                      formatter: '{c}{b}'
                    }
                  }
                }]
              },
              data: [
                ['2016/05/30 00:00:00', 31.0],
                ['2016/05/30 00:01:00', 31.0],
                ['2016/05/30 00:27:00', 30.6],
                ['2016/05/30 00:28:00', 30.5],
                ['2016/05/30 00:29:00', 30.5],
                ['2016/05/30 00:30:00', 30.5],
                ['2016/05/30 00:31:01', 30.5],
                ['2016/05/30 00:32:00', 30.6],
                ['2016/05/30 00:33:00', 30.6],
                ['2016/05/30 00:34:00', 30.6]
              ]
            }, 
            {
              name: '温度2',
              type: 'line',
              showSymbol: false,
              hoverAnimation: false,
              sampling: 'max',
              markLine: {
                symbol: ['none', 'none'],
                data: [{
                  name: '上限',
                  type: 'max',
                  yAxis: 31.0,
                  lineStyle: {
                    normal: {
                      color: '#FF3030'
                    }
                  },
                  label: {
                    normal: {
                      formatter: '{c}{b}'
                    }
                  }
                }, {
                  name: '下限',
                  type: 'min',
                  yAxis: 29.0,
                  lineStyle: {
                    normal: {
                      color: '#FF3030'
                    }
                  },
                  label: {
                    normal: {
                      formatter: '{c}{b}'
                    }
                  }
                }]
              },
              data: [
                ['2016/05/30 00:00:00', 30.6],
                ['2016/05/30 00:01:00', 30.7],
                ['2016/05/30 00:27:00', 30.7],
                ['2016/05/30 00:28:00', 30.6],
                ['2016/05/30 00:29:00', 30.7],
                ['2016/05/30 00:30:00', 30.7],
                ['2016/05/30 00:31:01', 30.7],
                ['2016/05/30 00:32:00', 30.8],
                ['2016/05/30 00:33:00', 30.8],
                ['2016/05/30 00:34:00', 30.9]
              ]
            }, 
            {
            name: '温度3',
            type: 'line',
            showSymbol: false,
            hoverAnimation: false,
            sampling: 'max',
            markLine: {
              symbol: ['none', 'none'],
              data: [{
                name: '上限',
                type: 'max',
                yAxis: 31.0,
                lineStyle: {
                  normal: {
                    color: '#FF3030'
                  }
                },
                label: {
                  normal: {
                    formatter: '{c}{b}'
                  }
                }
              }, {
                name: '下限',
                type: 'min',
                yAxis: 29.0,
                lineStyle: {
                  normal: {
                    color: '#FF3030'
                  }
                },
                label: {
                  normal: {
                    formatter: '{c}{b}'
                  }
                }
              }]
            },
            data: [
              ['2016/05/30 00:00:00', 30.8],
              ['2016/05/30 00:01:00', 30.8],
              ['2016/05/30 00:27:00', 30.9],
              ['2016/05/30 00:28:00', 30.9],
              ['2016/05/30 00:29:00', 30.9],
              ['2016/05/30 00:30:00', 31.0],
              ['2016/05/30 00:31:01', 30.7],
              ['2016/05/30 00:32:00', 30.8],
              ['2016/05/30 00:33:00', 30.8],
              ['2016/05/30 00:34:00', 30.9]
            ]}
      ]};

其他信息 (Other comments)

jjackychen avatar Jul 05 '16 02:07 jjackychen

可以用 path 字符串,例如

icon: 'path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z'

pissang avatar Jul 05 '16 03:07 pissang

path后面那一串是怎样得出来的?

jjackychen avatar Jul 05 '16 03:07 jjackychen

svg 文件里 path 元素的 d 属性

pissang avatar Jul 05 '16 03:07 pissang

我用在线转换器将图片转换成svg,将path元素的d属性复制

icon : 'path://M176 1038 c-3 -7 -39 -197 -81 -423 -42 -226 -79 -420 -82 -432 -5 -21 -2 -23 34 -23 l39 0 13 78 c20 122 9 112 116 112 l93 0 17 -95 17 -95 39 0 c37 0 38 1 33 28 -3 15 -40 214 -82 442 l-78 415 -37 3 c-24 2 -39 -1 -41 -10z m79 -368 c20 -118 38 -223 41 -232 5 -16 -3 -18 -80 -18 -47 0 -86 1 -86 3 0 1 18 106 40 232 22 127 40 235 41 240 2 22 10 -19 44 -225z',

页面上显示的icon倒转了,是什么原因呢?

jjackychen avatar Jul 05 '16 08:07 jjackychen

那就是这个 icon 确实就是倒着的吧,AI 或者其它工具编辑下就行

pissang avatar Jul 05 '16 08:07 pissang

但我在浏览器打开svg文件上看到是正着的啊,而且我用多个在线转换器转出来的svg代码复制过去也一样倒着。

jjackychen avatar Jul 05 '16 08:07 jjackychen

@pissang 请问toolbox引入自定义按钮的图标能否用相对路径,或者用require引入?

chj-damon avatar May 13 '17 03:05 chj-damon