0

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

8
  • Where do you initalize chart? Something like new Highcharts.Chart() or $("container").highcharts()? Commented Aug 7, 2014 at 11:45
  • yes am using highcharts for first time, please see my updated question i wrote a directive for highcharts Commented Aug 7, 2014 at 11:53
  • And what is your chart displaying? Try to change: data: [ data ] to data: data. Commented Aug 7, 2014 at 12:05
  • i did that but no use, my chart is not displaying at all Commented Aug 7, 2014 at 12:10
  • And do you have any errors in console? Do you see 'loading chart' in console? Commented Aug 7, 2014 at 12:11

1 Answer 1

1

I have solved my problem by doing following

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

Thank you

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.