vamsi
vamsi

Reputation: 1586

getting data from another function to display highcharts in angular

I am trying to display highcharts in my angular application Below is my get_chart function which takes data from another function

function get_chart(data) {
    alert('hello..' + data);

        return {
            xAxis: {
                categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
            },
            chart: {
                height: 300,
                width: 500,
                type: 'column'
            },
            credits: {
                enabled: false
            },
            plotOptions: {
                series: {
                    cursor: 'pointer',
                    point: {
                        events: {
                            click: function() {
                                console.log ('Category: '+ this.category +', value: '+ this.y);
                            }
                        }
                    }
                }
            },

            series: [{
                data:  [ data ] 
            }]
        };
    }

Then I am trying to send data from

$scope.renderChart = function(measurement){
        $scope.showChart = false;

        restApp.getMeasurementForCompID(comp.id, measurement.id).then(function(data){
            console.log('getMeasurementForCompID data ');
            console.log(data);
            data = [10, 20];

            $scope.example_chart = get_chart(data);
            console.log($scope.example_chart);

            $scope.showChart = true;
        });

    }

HTML

<div>
    <highchart id="dash-chart" chart='example_chart'></highchart>
    </div>

Highcharts directive

myapp.directive('highchart', function () {
return {
    restrict: 'E',
    template: '<div></div>',
    replace: true,

    link: function (scope, element, attrs) {

        scope.$watch(function() { return attrs.chart; }, function() {

            if(!attrs.chart) return;

            var chart = scope.example_chart;

            console.log('loading chart');
            console.log(chart);
            element.highcharts(chart);

        });

    }
}
});

console

enter image description here

But I am unable to display the charts with values 10,20. What might be the problem here?

Thanks

Upvotes: 0

Views: 692

Answers (1)

vamsi
vamsi

Reputation: 1586

I have solved my problem by doing following

<div>
<highchart ng-if="showChart" id="dash-chart" chart='example_chart'></highchart>
</div>

Thank you

Upvotes: 1

Related Questions