Echarts的使用总结

反向坐标轴

有时候做一些功能的折线图时需要使用到反向坐标轴(如排名的变化趋势)就需要用到Echarts的反向坐标轴的功能。

yAxis: {
    type: 'value',
    inverse: true, //y轴坐标轴向下
    axisLabel: {
        show: true,
        textStyle: {
            fontFamily: 'MaerskText-Regular',
        }
    },
},

执行Y轴反向后的Echarts图形

隐藏图表标题

可以使用如下代码或者直接删除这一条代码

title: {
    title: { text: null }, 
},

tooltip内容文字的样式设置

这里参考了一位博主的博客:echarts图中tooltip内容文字的样式设置
默认的tooltip就是一个div,直接在formatter里面添加span设置好颜色就可以了

tooltip: {
    backgroundColor: "#FFF", //设置tooltip的背景颜色颜色为白色(默认的为半透明黑色)
    borderColor: "#C3CBD6",	//修改边框线颜色(默认没有边框线颜色)
    borderWidth: 1,//修改边框线的宽度
    //axisPointer: { lineStyle: { color: "#C3CBD6" } },
    //formatter: '<span style="color: #657180; margin-left: 8px; float: right;">{a} <br/>{b} : {c}</span>' //内容显示格式
    textStyle: {//显示的字体颜色,样式以及大小
        fontSize: 12,
        color: '#657180',
        fontFamily: 'MaerskText-Regular'
    },
},

修改后的tooltip的样式
修改后的tooltip的样式
使用formatter改变数据显示方式(如添加百分号符号)

, formatter(params) {
    for (x in params) {
        return params[x].name + ":<br/>" + params[x].value+"%";
    }
}

使用formatter改变数据显示方式

雷达图

radar: {
    //shape: 'circle', //可以改变为圆弧形,默认是五角形
    name: {
        textStyle: {
            padding: [7, 7],//五个角的类别名离图形的上下左右距离
            color: '#2b425b',
            fontSize: 14,
            fontFamily: 'MaerskHeadline-Bold',
        },
    },//指示文字的样式
    indicator: nums,
},
series: [{
    symbolSize: 18, //五个角的圆圈大小
    name: 'Personal competence',
    type: 'radar',
    itemStyle: {
        normal: {
            color: 'red', //数值显示的颜色
            lineStyle: {
                color: '#29a4ff' //内部边框线的颜色,这里改为了蓝色
            }
        }
    },
    areaStyle: { normal: { color: '#ffffff' } },//内部区域图形的颜色
    data: [
        {
            value: values,
            label: {
                normal: {
                    show: true,
                    formatter: function (params) {
                        return params.value
                    }
                }
            }//折线上显示具体数值
        }
    ]
}]

在这里插入图片描述

柱形图(单一种类)

myChart.setOption(option);
option_Bar = {
    tooltip: {
        backgroundColor: "#FFF",
        borderColor: "#C3CBD6",
        borderWidth: 1,
        trigger: 'axis',
        axisPointer: {
            type: 'shadow'
        },
        textStyle: {
            fontSize: 12,
            color: '#657180',
            fontFamily: 'MaerskText-Regular'
        },
    },//tooltip的样式设置
    calculable: true,
    xAxis: [
        {
            type: 'category',
            axisLabel: {
                show: true,
                textStyle: {
                    fontFamily: 'MaerskText-Regular',
                }
            },
            data: nums_Bar,
        }
    ],//x轴的样式和数值
    yAxis: [
        {
            type: 'value',
            axisLabel: {
                show: true,
                textStyle: {
                    fontFamily: 'MaerskText-Regular',
                }
            },
        }
    ],//y轴的样式和数值
    series: [
        {
            barWidth: '20',
            name: 'Volume',
            type: 'bar',
            data: values_Bar,
            itemStyle: {
                normal: {
                    color: '#43afd4', //柱形图的颜色设置,这里为蓝色
                    label: {
                        show: true,//是否在柱形图上显示数值
                        position: 'top',//设置柱形图数值显示的位置,这里设置在柱形图的顶部
                        formatter: '{c}',//柱形图数值的的格式,这里只让它显示了数值,当然也可以显示类名等等
                        fontFamily: 'MaerskText-Regular',//数值显示的字体样式
                        fontSize: 12,//数值显示的的字体大小
                    }
                },
            },
        },
    ]
};
myChart_Bar.setOption(option_Bar);

cgart柱形图

柱状图(多种类)

与只有一个种类的柱形图相比,多种类的需要再series中添加更多的数据源

var myChart = echarts.init(document.getElementById('Bar'));
option = {
    title: {
        text: 'TOP 10 IN THE TEAM',
        textStyle: {
            fontSize: 16,
            fontFamily: 'MaerskHeadline-Regular',
        }
    },
    color: ['#43afd4', '#13253b', '#878787'],//柱形图的颜色
    tooltip: {
        backgroundColor: "#FFF",
        borderColor: "#C3CBD6",
        borderWidth: 1,
        trigger: 'axis',
        formatter: function (params) {
            var res = '<div><p>' + params[0].name + '</p></div>'
            for (var i = 0; i < params.length; i++) {
                if (i==2) {
                    res += '<p>' + params[i].seriesName + ':' + params[i].data + '%</p>'
                } else {
                    res += '<p>' + params[i].seriesName + ':' + params[i].data + '</p>'
                }
            }
            return res;
        },
        textStyle: {
            fontSize: 12,
            color: '#657180',
            fontFamily: 'MaerskText-Regular'
        },
    },
    legend: {
        y: '0px',
        data: ['Total Score', 'Accuracy', 'Production']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    toolbox: {
        show: true,
        orient: 'vertical',
        left: 'right',
        top: 'center',
        feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            saveAsImage: { show: true }
        }
    },
    calculable: true,
    xAxis: [
        {
            type: 'category',
            axisLabel: {
                show: true,
                textStyle: {
                    fontFamily: 'MaerskText-Regular',
                }
            },
            data: names,
        }
    ],
    yAxis: [
        {
            type: 'value',
            axisLabel: {
                show: true,
                textStyle: {
                    fontFamily: 'MaerskText-Regular',
                }
            },
        }
    ],
    series: [
        {
            barWidth: '15',
            name: 'Total Score',
            type: 'bar',
            barGap: 0,
            data: AVGScore,
            itemStyle: {
                normal: {
                    label: {
                        show: true,
                        position: 'top',
                        formatter: '{c}',
                        fontFamily: 'MaerskText-Regular',
                    }
                },
            },
        },
        {
            barWidth: '15',
            name: 'Accuracy',
            type: 'bar',
            data: AVGAcc,
            itemStyle: {
                normal: {
                    label: {
                        show: true,
                        position: 'top',
                        formatter: '{c}',
                        fontFamily: 'MaerskText-Regular',
                    }
                },
            },
        },
        {
            barWidth: '15',
            name: 'Production',
            type: 'bar',
            data: AVGPro,
            itemStyle: {
                normal: {
                    label: {
                        show: true,
                        position: 'top',
                        formatter: '{c}%',
                        fontFamily: 'MaerskText-Regular',
                    }
                },
            },
        },
    ]
};
myChart.setOption(option);

在这里插入图片描述

折线图(单一种类折现趋势)

option_RankLine = {
    tooltip: {
        backgroundColor: "#FFF",
        borderColor: "#C3CBD6",
        borderWidth: 1,
        textStyle: {
            fontSize: 12,
            color: '#657180',
            fontFamily: 'MaerskText-Regular'
        },
        trigger: 'axis'
    },
    toolbox: {
        show: true,
        orient: 'vertical',
        left: 'right',//显示在图形的最右边
        top: 'center',
        feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },//数据视图,即以表格的方式显示折线的数据
            magicType: { show: true, type: ['line', 'bar', 'stack', 'tiled'] },//切换为折线图,柱形图,堆叠图按钮
            restore: { show: true },//充型加载数据按钮
            saveAsImage: { show: true }//下载图片按钮
        }
    },//侧边的工具栏
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },//图形到容器div的距离
    xAxis: {
        type: 'category',
        axisLabel: {
            show: true,
            textStyle: {
                fontFamily: 'MaerskText-Regular',
            }
        },
        boundaryGap: false,
        data: rank_weeknum,
    },
    yAxis: {
        type: 'value',
        inverse: true,//反向y轴
        axisLabel: {
            show: true,
            textStyle: {
                fontFamily: 'MaerskText-Regular',
            }
        },
    },
    series: [
        {
            name: 'Rank',
            type: 'line',
            data: rank_num,
            itemStyle: {
                normal: {
                    color: '#43afd4',
                    label: {
                        show: true,
                        position: 'top',
                        formatter: '{c}',
                        fontFamily: 'MaerskText-Regular',
                    }
                },
            },
        },
    ]
};
myChart_RankLine.setOption(option_RankLine);

单一种类折线图

折线图(多种类)

多种类折线图和单一折线图和多种类的折线图的区别是series中的数据类别更多,折线就会出现多条折线

myChart_Line.setOption({
    title: {
        text: 'Historical case data',
        textStyle: {
            fontSize: 16,
            fontFamily: 'MaerskHeadline-Regular',
        }
    },
    tooltip: {
        backgroundColor: "#FFF",
        borderColor: "#C3CBD6",
        borderWidth: 1,
        textStyle: {
            fontSize: 12,
            color: '#657180',
            fontFamily: 'MaerskText-Regular'
        },
        trigger: 'axis'
    },
    color: ['#878787', '#00786b', '#f46a55', '#cecece', '#13253b', '#43afd4'],//设置各类别折线的颜色
    legend: {
        data: ["AMD booking", "Case", "Doc", "Fresh booking", "Report", "VAS report"]
    },//显示在顶部的类别提示
    toolbox: {
        show: true,
        orient: 'vertical',
        left: 'right',
        top: 'center',
        feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            //magicType: { show: true, type: ['line', 'bar', 'stack', 'tiled'] },
            //restore: { show: true },
            saveAsImage: { show: true }
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        type: 'category',
        boundaryGap: false,
        data: names_date
    },
    yAxis: {
        type: 'value'
    },
    series: [
        {
            name: 'AMD booking',
            type: 'line',
            stack: '总量',
            data: nums_All_AMD_booking
        },
        {
            name: 'Case',
            type: 'line',
            stack: '总量',
            data: nums_All_case
        },
        {
            name: 'Doc',
            type: 'line',
            stack: '总量',
            data: nums_All_Doc
        },
        {
            name: 'Fresh booking',
            type: 'line',
            stack: '总量',
            data: nums_All_Fresh_booking
        },
        {
            name: 'Report',
            type: 'line',
            stack: '总量',
            data: nums_All_Report
        },
        {
            name: 'VAS report',
            type: 'line',
            stack: '总量',
            data: nums_All_VAS_report
        }
    ]
});

多条折线

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Echarts是一个优秀的数据可视化库,可以帮助开发者快速构建各种图表和数据展示的界面。在使用Echarts时,我们通常会用到v-show这个指令来控制图表的显示和隐藏。 v-show是Vue.js框架中的一个指令,用于根据表达式的值来控制DOM元素的显示和隐藏。当表达式的值为真时,DOM元素会显示出来;当表达式的值为假时,DOM元素会隐藏起来。 在使用Echarts时,可以将图表所在的DOM元素与v-show指令结合使用,通过改变表达式的值来控制图表的显示和隐藏。 例如,假设有一个按钮来控制图表的显示和隐藏,通过点击按钮可以改变一个布尔类型的变量showChart的值。通过在图表所在的DOM元素上添加v-show指令,设置表达式为showChart,就可以实现根据showChart变量的值来显示或隐藏图表。 ``` <template> <div> <button @click="toggleChart">点击切换图表显示</button> <div v-show="showChart" id="chart"></div> </div> </template> <script> export default { data() { return { showChart: true, // 其他图表相关的配置 } }, methods: { toggleChart() { this.showChart = !this.showChart; }, // 其他方法和事件处理逻辑 }, mounted() { // 初始化Echarts图表 const chart = echarts.init(document.getElementById('chart')); // 图表的相关配置和数据处理逻辑 // ... } } </script> ``` 通过上述代码,可以实现点击按钮切换图表的显示和隐藏效果。当showChart变量为真时,图表会显示出来;当showChart变量为假时,图表会隐藏起来。 总结来说,使用v-show可以方便地控制Echarts图表的显示和隐藏,提升了页面的交互性和用户体验。同时,结合Vue.js框架的特性,可以更加灵活地处理图表的显示和隐藏逻辑。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值