0

i am trying to make a pie chart directive and i use the highcharts one but i also want to add another line of text that sais for example '60%' or so. So far i tried this

app.directive('pieGraph', function($compile) {
  return {
    restrict: 'C',
    scope: {
      value: '@',
      color: '@'
    },
    link: function(scope, elem) {
      elem.highcharts({
        chart: {
          type: 'pie',
          backgroundColor: null
        },
        title: {
          text: null
        },
        yAxis: {
          title: {
            text: 'Total percent market share'
          }
        },
        plotOptions: {
          pie: {
            shadow: true
          }
        },
        legend: {
          enabled: false
        },
        credits: {
          enabled: false
        },
        exporting: {
          enabled: false
        },
        tooltip: {
          enabled: false
        },
        series: [{
          name: '',
          data: [
            {
              name: 'a',
              y: parseInt(scope.value, 10),
              color: scope.color
            },
            {
              name: 'b',
              y: (100 - parseInt(scope.value, 10)),
              color: '#ffffff'
            }
          ],
          size: '100%',
          innerSize: '90%',
          dataLabels: {
            enabled: false
          }
        }]
      });

      var graph = angular.element('<span class="pie-graph-value">{{scope.value}}<sup>%</sup></span>');
      $compile(graph)(scope);
      elem.append(graph);
    }
  };
});

but this issue is that the last that i applied, sais only % instead the value and percent symbol. Is there something wrong i did on the compile stuff on the end ?

Thank you in advance, Daniel!

1 Answer 1

1

Either use {{value}} or write your element as '<span class="pie-graph-value">' + scope.value + '<sup>%</sup></span>' (note the latter will not update later since the value is only calculated once when appending the element). This element will be rendered so the reference to scope is implicit.

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

1 Comment

oh my god man, i can't believe i wrote scope inside the html :) thank you so much mate, this answer helped me ALOT !

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.