【问题标题】:highchart's hidden chart renders out of container in Angularjshighchart的隐藏图表在Angularjs中渲染出容器
【发布时间】:2015-01-10 02:16:28
【问题描述】:

我正在尝试创建一个完整的响应式 highchart 饼图,该饼图位于一个用ng-show 隐藏的 div 内。

我已经阅读过有关如何使用 jquery 解决此问题的类似问题:(onetwothree

我试过了:

  1. $(window).resize() 但没用
  2. $scope.$apply() 工作,但它一直抛出一个已经消化的循环错误
  3. 我可以使用高图表的属性width : "string" 指定宽度,但图表不会响应并始终保持相同的宽度。

Here is a Plunker of the error

注意:只要把视图窗口足够大,这样当你按下按钮的时候,你就可以看到图表在div的顶部。

【问题讨论】:

    标签: jquery css angularjs twitter-bootstrap highcharts


    【解决方案1】:

    最好使用 https://github.com/pablojim/highcharts-ng 等高库存的角度包装器之一或创建如下指令来达到目的

    <div high-chart id="chart" chartData="chart" style="height: 400px; min-width: 310px">
    </div>
    

    将数据绑定到控制器中的“图表”并创建指令,

    .directive('highChart',function(){
    
          return{
            restrict:'A',
            scope:{
              chart:'=chartdata'
            },
            link:function(scope,element,attrs){
              scope.$watch('chart',function(newV){
                if(newV){
                $('#chart').highcharts('StockChart', {
                    rangeSelector : {
                        inputEnabled: $('#chart').width() > 480,
                        selected : 1
                    },
    
                    title : {
                        text : 'AAPL Stock Price'
                    },
    
                    series : [{
                        type : 'scatter',
                        name : 'AAPL Stock Price',
                        data : newV,
                        dataGrouping : {
                            units : [
                                [
                                    'week', // unit name
                                    [1] // allowed multiples
                                ], [
                                    'month',
                                    [1, 2, 3, 4, 6]
                                ]
                            ]
                        }
                    }]
                });
                }
              })
            }
          }
        })
    

    希望对您有所帮助。

    【讨论】:

    • 感谢您的回答,我会试试这个并告诉您它是否有效
    • 嗨 @32teeths 我尝试使用 highcharts-ng 但它不是响应式的,他使用固定宽度的方法,我在互联网上找不到他的指令的示例响应式行为,感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-10
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多