javascript - 更改Highchart堆积柱形图的样式

标签 javascript highcharts

我绘制了一个堆积柱形 Highcharts 。该图表工作正常,但存在一些样式问题。 Y 轴名称显示在图表上方,因此未显示副标题我需要在下面显示 Y 轴名称。我该如何更改此设置?提前感谢您的帮助...

这是我的代码

 <script type="text/javascript">

    $(function () {
        $('#chart_div').highcharts({
            chart: {
                type: 'column'
            },
            title: {
                text: 'Material Vs Subcategory'
            },
            subtitle: {
                text: 'Source: www.test.com'
            },
            xAxis: {
                categories: ['Air Filtration','Clothing','Sporting Goods','Home Furnishings','Paint','Storage','Toys and Games']
            },
            yAxis: {
                min: 0,
                title: {
                    text: 'Number of Products'
                },
                stackLabels: {
                    enabled: true,
                    style: {
                        fontWeight: 'bold',
                        color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
                    }
                }
            },
            legend: {
                align: 'right',
                x: -70,
                verticalAlign: 'top',
                y: 20,
                floating: true,
                backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
                borderColor: '#CCC',
                borderWidth: 1,
                shadow: false
            },
            tooltip: {
                formatter: function () {
                    return '<b>' + this.x + '</b><br/>' +
                        this.series.name + ': ' + this.y + '<br/>' +
                        'Total: ' + this.point.stackTotal;
                }
            },
            plotOptions: {
                column: {
                    stacking: 'normal',
                    dataLabels: {
                        enabled: false,
                        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
                    }
                }
            },

            series: [{
             name: 'Unclassifiable',
             data: [0, 1, 0, 0, 1, 0, 0]
         },{
                  name: 'Aluminium',
                  data: [0, 0, 0, 0, 0, 0, 0]
             },{
                  name: 'Calcium',
                  data: [0, 0, 0, 1, 0, 0, 0]
              },{
                  name: 'Copper',
                  data: [0, 0, 0, 0, 0, 0, 0]
              },{
                  name: 'Gold',
                  data: [0, 1, 0, 0, 1, 1, 0]
              },{
                  name: 'Iron',
                  data: [0, 0, 0, 0, 0, 0, 0]
              },{
                  name: 'Platinum',
                  data: [0, 0, 0, 0, 1, 0, 1]
              },{
                  name: 'Silver',
                  data: [0, 3, 3, 0, 0, 0, 0]
              },{
                  name: 'Steel',
                  data: [1, 0, 0, 1, 0, 0, 0]
              },{
                  name: 'Unknown',
                  data: [0, 1, 0, 0, 1, 0, 0]
              }]

        });
    });

</script>

最佳答案

去掉“ float ”和 x/y 位置也使它看起来更干净:

    legend: {
        verticalAlign: 'bottom',
        backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
        borderColor: '#CCC',
        borderWidth: 1,
        shadow: false
    },

http://jsfiddle.net/38Mkf/1/

关于javascript - 更改Highchart堆积柱形图的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20882619/

相关文章:

javascript - 在 highcharts/highstock 中添加自定义下拉菜单

javascript - 导出上下文按钮时缺少 Highcharts CSS 样式

javascript - 从导出菜单打印图表时隐藏滚动条

javascript - 带有异步返回 Promise 的 Map

javascript - 如何使用asp.net动态添加链接按钮并在gridview中传递参数?

Javascript getElementById 查找 - HashMap 或递归树遍历?

javascript - highcharts 没有点标记,但显示单点或不连续点

javascript - 无法加载资源:net::ERR_CONTENT_LENGTH_MISMATCH(PHP错误)

Javascript - 动态 div 宽度取决于页面大小

javascript Highcharts JSON 数据到 HTML 表格