美文网首页
双向柱形图

双向柱形图

作者: 奶酪凌 | 来源:发表于2022-01-19 09:19 被阅读0次
image.png
    var xData = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
    var lineData = [100, 100, 100, 100, 100, 100, 100]
    var lastYearData = [3, 20, 62, 34, 55, 65, 33];
    var thisYearData = [11, 38, 23, 39, 66, 66, 79];
    var timeLineData = [1];
    let legend=['2017', '2018'];
    var background = "#0e2147"; //背景 
    let textColor = "#fff";
    let lineColor="rgba(255,255,255,0.2)";
    let colors = [{
            borderColor: "rgba(227,161,96,1)",
            start: "rgba(227,161,96,0.8)",
            end: "rgba(227,161,96,0.3)"
        },
        {
            borderColor: "rgba(0,222,255,1)",
            start: "rgba(0,222,255,0.3)",
            end: "rgba(0,222,255,0.8)"
        },
    ];
    let borderData = [];
    let scale = 2;
    borderData = xData.map(item => {
        return scale;
    });
    var option = {
        baseOption: {
            backgroundColor: background,
            timeline: {
                show: false,
                top: 0,
                data: []
            },
            legend: {
                top: '5%',
                right: '5%',
                itemWidth: 20,
                itemHeight: 5,
                // itemGap: 343,
                icon: 'horizontal',
                textStyle: {
                    color: '#ffffff',
                    fontSize: 20,
                },
                data: legend
            },
            grid: [{
                show: false,
                left: '5%',
                top: '10%',
                bottom: '8%',
                containLabel: true,
                width: '37%'
            }, {
                show: false,
                left: '51%',
                top: '10%',
                bottom: '8%',
                width: '0%'
            }, {
                show: false,
                right: '2%',
                top: '10%',
                bottom: '8%',
                containLabel: true,
                width: '37%'
            }],
            xAxis: [{
                type: 'value',
                inverse: true,
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                position: 'top',
                axisLabel: {
                    show: true,
                    color: textColor
                },
                splitLine:{
                     show: true,
                    lineStyle:{
                        color:lineColor
                    }
                },
            }, {
                gridIndex: 1,
                show: false
            }, {
                gridIndex: 2,
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                position: 'top',
                axisLabel: {
                    show: true,
                    color: textColor
                },
                 splitLine:{
                     show: true,
                    lineStyle:{
                        color:lineColor
                    }
                },
            }],
            yAxis: [{
                type: 'category',
                inverse: true,
                position: 'right',
                axisLine: {
                    show: true,
                    lineStyle:{
                        color:lineColor
                    }
                },
               
                axisTick: {
                    show: false
                },
                axisLabel: {
                    show: false
                },
                data: xData
            }, {
                gridIndex: 1,
                type: 'category',
                inverse: true,
                position: 'left',
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    show: true,
                    padding:[30,0,0,0],
                    textStyle: {
                        color: '#ffffff',
                        fontSize: 20
                    },
                    align: "center"

                },
                data: xData.map(function(value) {
                    return {
                        value: value,
                        textStyle: {
                            align: 'center'
                        }
                    }
                })
            }, {
                gridIndex: 2,
                type: 'category',
                inverse: true,
                position: 'left',
                axisLine: {
                     show: true,
                    lineStyle:{
                        color:lineColor
                    }
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    show: false

                },
                data: xData
            }],
            series: []

        },
        options: []
    }

    option.baseOption.timeline.data.push(timeLineData[0])
    option.options.push({
        series: [{
                name: "2017",
                type: "bar",
                barWidth: 25,
                stack: "1",
                itemStyle: {
                    normal: {
                        color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                                offset: 0,
                                color: colors[0].start
                            },
                            {
                                offset: 1,
                                color: colors[0].end
                            }
                        ]),
                    }
                },
                label: {
                    normal: {
                        show: false,
                    }
                },
                data: lastYearData,
                animationEasing: "elasticOut"
            },
            {
                name: "2017",
                type: "bar",
                barWidth: 25,
                stack: "1",
                itemStyle: {
                    normal: {
                        color: colors[0].borderColor

                    }
                },
                data: borderData
            },
            {
                name: "2018",
                type: "bar",
                stack: "2",
                barWidth: 25,
                xAxisIndex: 2,
                yAxisIndex: 2,
                itemStyle: {
                    normal: {
                        color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                                offset: 0,
                                color: colors[1].start
                            },
                            {
                                offset: 1,
                                color: colors[1].end
                            }
                        ]),
                    }
                },
                label: {
                    normal: {
                        show: false,
                    }
                },
                data: thisYearData,
                animationEasing: "elasticOut"
            },
            {
                name: "2018",
                type: "bar",
                xAxisIndex: 2,
                yAxisIndex: 2,
                barWidth: 25,
                stack: "2",
                itemStyle: {
                    normal: {
                        color: colors[1].borderColor

                    }
                },
                data: borderData
            },
        ]
    });

相关文章

  • 双向柱形图

  • python matplotlib(pymatplotlib)

    堆叠柱形图 并列柱形图 水平柱形图 破损柱形图 分类变量图 堆叠柱形图 并列柱形图 水平柱形图 破损柱形图 分类变量图

  • echarts

    项目安装 线形图 柱形图 横向柱形图 饼图

  • 数据分析图表类之花式运用“柱状图”

    柱形图是我们最常用的一类图表,常用来分析每类数据“有多少”的问题。柱形图又可以延伸为簇状柱形图、堆积柱形图、百分比...

  • Python强大的pyecharts绘画优美图形<二>

    常用图形:柱形图-折线图-饼图-散点图 柱形图 对应的图像如下 折线图 对应图形如下 柱形图-折线图 饼图 散点图...

  • 柱形图在PPT里的美化

    哈喽,大家好,我是诗珑。 今天给大家分享的是图表——柱形图在PPT中的美化。 柱形图主要包括:簇状柱形图、堆积柱形...

  • 5分钟教你用python制作带精美图形的PPT

    本 5分钟系列将会讲解如何在python中如何自动在PPT里画柱形图,并将其扩展为多柱形图。最后给每个柱形图标上对...

  • R语言绘图合集

    一、类别比较型图 [R-柱形图系列] R-柱形图[http://mp.weixin.qq.com/s?__biz=...

  • ggplot2应用(一)——柱形图

    前言 柱形图属于类别比较型图表,包括单数据系列柱状图、多数据系列柱状图、堆积柱状图和百分比堆积柱形图。柱形图一般适...

  • WPS表格:火箭柱形图

    火箭柱图 本篇适合:已适配小白。 QQ交流群:644328490。 需求:生成图-1的火箭柱形图: 关键词:柱形图...

网友评论

      本文标题:双向柱形图

      本文链接:https://www.haomeiwen.com/subject/tmqrhrtx.html