【问题标题】:Highcharts drill down marginHighcharts 向下钻取保证金
【发布时间】:2018-03-31 22:15:02
【问题描述】:

不幸的是,向上钻取按钮通常位于图表顶部。我想将 marginTop 应用于向下钻取图,以便该图始终位于按钮下方。我用过这个example。如您所见,该按钮位于柱形图的顶部。 HTML

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/drilldown.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

JavaScript

$(function() {

// Create the chart
$('#container').highcharts({
chart: {
  type: 'column',
  events: {
    drilldown: function(e) {
      if (!e.seriesOptions) {
        var drilldowns = {
          'animals': {
            name: 'Cats',
            color: '#fa7921',
            drilldown: 'Cats',
            data: [
              ['2014', 10],
              ['2015', 10],
              ['2016', 15],
            ]
          }
        },
            drilldowns2 = {
              'animals': {
                name: 'Cows',
                color: '#9bc53d',
                data: [
                  ['2014', 13],
                  ['2015', 15],
                  ['2016', 15]
                ]
              }
            },
            drilldowns3 = {
              'animals': {
                name: 'Sheep',
                color: '#e55934',
                data: [
                  ['2014', 13],
                  ['2015', 15],
                  ['2016', 15]
                ]
              }
            };

        this.addSingleSeriesAsDrilldown(e.point, drilldowns[e.point.name]);
        this.addSingleSeriesAsDrilldown(e.point, drilldowns2[e.point.name]);
        this.addSingleSeriesAsDrilldown(e.point, drilldowns3[e.point.name]);
        this.applyDrilldown();
      }
    }
  }
},
title: {
  text: 'Async drilldown'
},
xAxis: {
  type: 'category'
},

legend: {
  enabled: false
},

plotOptions: {
  series: {
    stacking: 'normal',
    borderWidth: 0,
    dataLabels: {
      enabled: true
    }
  }
},

series: [{
  name: 'Cats',
  color: '#fa7921',
  data: [{
    name: 'animals',
    y: 5,
    drilldown: true
  }]
}, {
  name: 'Cows',
  color: '#9bc53d',
  data: [{
    name: 'animals',
    y: 5,
    drilldown: true
  }]
}, {
  name: 'Sheep',
  color: '#e55934',
  data: [{
    name: 'animals',
    y: 5,
    drilldown: true
  }]
}],

drilldown: {
  series: []
}
});
});

希望有人知道一个简单的解决方案。

【问题讨论】:

    标签: jquery highcharts settings drilldown


    【解决方案1】:

    drilldown 事件中更新图表的marginTop

            this.update({
              chart: {
                marginTop: 50
              }
            }, false);
    

    并在drillup事件中恢复它:

          this.update({
            chart: {
              marginTop: 10
            }
          }, false);
    

    现场演示: http://jsfiddle.net/BlackLabel/a0va2b1x/

    注意update() 的第二个参数是false - 这里不需要重绘图表。

    【讨论】:

    • 谢谢,这正是我想要的!
    【解决方案2】:

    查看drilldown.drillUpButton 文档

    更新你的drilldown

       drilldown: {
          drillUpButton: {
            relativeTo: 'spacingBox',
            position: {
              y: 0,
              x: 0
            }
          },
          series: []
        }
    

    $(function() {
    
      // Create the chart
      $('#container').highcharts({
        chart: {
          type: 'column',
          events: {
            drilldown: function(e) {
              if (!e.seriesOptions) {
                var drilldowns = {
                    'animals': {
                      name: 'Cats',
                      color: '#fa7921',
                      drilldown: 'Cats',
                      data: [
                        ['2014', 10],
                        ['2015', 10],
                        ['2016', 15],
                      ]
                    }
                  },
                  drilldowns2 = {
                    'animals': {
                      name: 'Cows',
                      color: '#9bc53d',
                      data: [
                        ['2014', 13],
                        ['2015', 15],
                        ['2016', 15]
                      ]
                    }
                  },
                  drilldowns3 = {
                    'animals': {
                      name: 'Sheep',
                      color: '#e55934',
                      data: [
                        ['2014', 13],
                        ['2015', 15],
                        ['2016', 15]
                      ]
                    }
                  };
    
                this.addSingleSeriesAsDrilldown(e.point, drilldowns[e.point.name]);
                this.addSingleSeriesAsDrilldown(e.point, drilldowns2[e.point.name]);
                this.addSingleSeriesAsDrilldown(e.point, drilldowns3[e.point.name]);
                this.applyDrilldown();
              }
            }
          }
        },
        title: {
          text: 'Async drilldown'
        },
        xAxis: {
          type: 'category'
        },
    
        legend: {
          enabled: false
        },
    
        plotOptions: {
          series: {
            stacking: 'normal',
            borderWidth: 0,
            dataLabels: {
              enabled: true
            }
          }
        },
    
        series: [{
          name: 'Cats',
          color: '#fa7921',
          data: [{
            name: 'animals',
            y: 5,
            drilldown: true
          }]
        }, {
          name: 'Cows',
          color: '#9bc53d',
          data: [{
            name: 'animals',
            y: 5,
            drilldown: true
          }]
        }, {
          name: 'Sheep',
          color: '#e55934',
          data: [{
            name: 'animals',
            y: 5,
            drilldown: true
          }]
        }],
    
        drilldown: {
          drillUpButton: {
            relativeTo: 'spacingBox',
            position: {
              y: 0,
              x: 0
            }
          },
          series: []
        }
      });
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/modules/drilldown.js"></script>
    <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

    【讨论】:

    • 嗨 Deep 3015,再次感谢您的回复。我看到我在我的例子中并不完整。没有标题,所以图表向上移动。请参阅我在您的调整中处理的完整示例。 jsfiddle.net/Pension007/oq9hLbwu
    • 在图表参数中添加marginTop: 50,jsfiddle.net/L60ned6k
    • 再次坦克,但我只想要下钻柱的边距而不是第一张图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多