简体   繁体   English

高图试图隐藏/显示系列

[英]Highcharts Trying to Hide/Show series

I have an Angular webapp that I am using Highcarts with to display data. 我有一个使用Highcarts来显示数据的Angular webapp。 The chart is configured like the following initially. 最初,该图表的配置如下。 In a controller (I use Coffeescript) 在控制器中(我使用Coffeescript)

$scope.chartConfig = {
        options:
            chart:
                type: 'spline'
                plotBackgroundColor: null
            legend:
                enabled: true
            title:
                text: ''
            subtitle:
                text: ''
            exporting:
                url: $config.exportAddress
                width: 1000
        series: [{
             name: ''
            data: [
            ]
            },{
            name: ''
            data: [
            ]
            }]
        loading: false
        xAxis:
            categories: [
            ]
            title:
                text: ''
        yAxis:
            title:
                text: ''
        useHighStocks: false
        size:
            height: 500
    }

And displayed in the HTML using 并显示在HTML中

<div class="panel-body" id="report-display normalchart" ng-if="!productMonthlyChart">
   <highchart id="chart1" config="chartConfig"></highchart>
</div>

Using a function I push data into the chart like the following 使用函数将数据推入图表,如下所示

$scope.chartConfig.series.length = 0
        # Set title and chart time and and name
        $scope.chartConfig.xAxis.categories = ['Build Overview']
        $scope.chartConfig.options.chart.type = 'column'
        $scope.graphName = 'Column Chart'
        $scope.chartConfig.series.push({name: 'Admitted', data: [$scope.fullBuildTotals.admitted]})
        $scope.chartConfig.series.push({name: 'Deprecated', data: [$scope.fullBuildTotals.deprecated]})

I need to be able to show and hide series on the chart however I cannot get it to work using the following show or hide code 我需要能够在图表上显示和隐藏序列,但是无法使用以下显示或隐藏代码来使其工作

$scope.chartConfig.series[0].show()
$scope.chartConfig.series[0].hide()

I get the following error in the console 我在控制台中收到以下错误

TypeError: $scope.chartConfig.series[0].hide is not a function at Scope.$scope.showCurrentBuildReportChartData TypeError:$ scope.chartConfig.series [0] .hide不是Scope。$ scope.showCurrentBuildReportChartData的函数

Does anyone have any idea why this may be happening? 有谁知道为什么会这样? I also came across code where you select the DIV the Chart is contained in call a highcharts() function on it to get the chart but that did not work either. 我还遇到了一些代码,在这些代码中,您选择了Chart包含的DIV,该DIV包含在对其调用highcharts()函数以获取图表中,但是这也不起作用。

Found a solution, not sure why series[0].show() and .hide() didn't work but an alternative is to directly do what those functions do anyway. 找到了一个解决方案,不知道为什么为什么series [0] .show()和.hide()不起作用,但是另一种方法是直接执行这些函数的操作。

$scope.chartConfig.series[0].visible = true
$scope.chartConfig.series[0].visible = false

The above code works perfectly. 上面的代码工作完美。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM