Search code examples
angularjsd3.jschartsnvd3.jsangular-nvd3

Angular nvd3 HorizontalBarChart displayed difference format in the barLine and the holizontalLine


I am creating a chart which using Angular-nvd3 library which base on nvd3 and d3.js and I have a problem that I want to display the percent in the chart barLine and the total number in the chart horizontalLIne something looks like this: enter image description here

But currently, I don't know how to do that. I have created a plnkr: [http://plnkr.co/edit/PygsTn?p=preview][2]

Hope I can get some help. Thank you for taking time to look at my question.


Solution

  • You can do it with valueFormat property:

    chart: {
        valueFormat: function(value){
            return Math.floor(value/TOTAL * 100) + "%";
        }
    }
    

    Modified plunker: http://plnkr.co/edit/ilaNl5KEqZa02HbWby9s?p=preview