dongne1560 2013-07-18 20:21
浏览 57
已采纳

如何将相同的高级系列放在一起

i am using highcharts for drawing column charts

i have a column chart with multiple series like this

enter image description here

and this is my code :

$(function () {
        var chart;
        $(document).ready(function() {
                // Radialize the colors
                Highcharts.getOptions().colors = Highcharts.map(Highcharts.getOptions().colors, function(color) {
                    return {
                        radialGradient: { cx: 0.5, cy: 0.3, r: 0.7 },
                        stops: [
                            [0, color],
                            [1, Highcharts.Color(color).brighten(-0.2).get("rgb")]
                        ]
                    };
                });

                chart = new Highcharts.Chart({
                chart: {
                    renderTo: "container"
                },
                title: {
                    text: "نمودار کلی عملکرد داوطلب",
                    style:
                    {
                        direction: "rtl",
                        fontSize: "16px"
                    }
                },
                yAxis: {
                    min: -33.3,
                    max: 100,
                    startOnTick: false,
                    title: {
                        enabled: true,
                        text: "درصد"
                    }
                },
                xAxis: {
                    categories: [' . implode(",", $chartCats) . ']
                },
                tooltip: {
                    formatter: function() {
                        return this.series.name+"<br/>% "+this.point.y+"<br/>";
                    }
                },
                plotOptions: {
                    column: {
                        dataLabels: {
                            enabled: true
                        },
                        pointWidth: 20
                    },
                    series: {
                        animation: {
                            duration: 3000
                        }
                    }
                },
                credits: {
                    enabled: false
                },
                series:
                [' . $chartData . ']
            });
        });
    });

how can i place all columns with same color beside each other?

for example : all blue columns beside each other then all red column beside each other

  • 写回答

1条回答 默认 最新

  • douyi3760 2013-07-19 11:21
    关注

    In general something like this is not supported, however you can split data into different arrays, as each column will be one series, just linked to 'master' one, see: http://jsfiddle.net/CVvjZ/

    Of course this has limitations, since you need to pre calculate values for for x:

        xAxis: {
            min: 0,
            startOnTick: true,
            max: 1,
            endOnTick: true,
            categories: ['Jan', 'Feb', 'Mar']
        },
        plotOptions: {
            column: {
                grouping: false,
                pointWidth: 20
            }
        },
        series: [{
            color: colors[0],
            name: 'Tokyo',
            id: 'tokyo',
            data: [[0.3, 15]]
        }, {
            color: colors[0],
            name: 'Tokyo',
            linkedTo: 'tokyo',
            data: [[0, 10]]
        }, {
            color: colors[0],
            name: 'Tokyo',
            linkedTo: 'tokyo',
            data: [[-0.3, 10]]
        },{
            color: colors[1],
            name: 'Osaka',
            id: 'osaka',
            data: [[1.3, 15]]
        }, {
            color: colors[1],
            name: 'Osaka',
            linkedTo: 'osaka',
            data: [[1, 10]]
        }, {
            color: colors[1],
            name: 'Osaka',
            linkedTo: 'osaka',
            data: [[0.7, 10]]
        }]
    

    There is also second solution, a little easier is to use stacking options instead of calculating values: http://jsfiddle.net/CVvjZ/1/

    And code:

    xAxis: {
            categories: ['Jan', 'Feb', 'Mar']
        },
        plotOptions: {
            column: {
                stacking: 'normal'
            }
        },
        series: [{
            color: colors[0],
            stack: 1,
            name: 'Tokyo',
            id: 'tokyo',
            data: [15]
        }, {
            color: colors[0],
            stack: 2,
            name: 'Tokyo',
            linkedTo: 'tokyo',
            data: [15]
        }, {
            color: colors[0],
            stack: 3,
            name: 'Tokyo',
            linkedTo: 'tokyo',
            data: [11]
        },{
            color: colors[1],
            stack: 1,
            name: 'Osaka',
            id: 'osaka',
            data: [[1,12]]
        }, {
            color: colors[1],
            stack: 2,
            name: 'Osaka',
            linkedTo: 'osaka',
            data: [[1,13]]
        }, {
            color: colors[1],
            stack: 3,
            name: 'Osaka',
            linkedTo: 'osaka',
            data: [[1,14]]
        }]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值