4

我只想让我的图例具有左对齐的名称值和右对齐的百分比值,我已经连续 2 天在这件事上工作,并在论坛上打开了几个不同的问题,并且得到了 0 个答案,所以任何有任何知识的人我很想得到你的帮助!非常感谢 http://jsfiddle.net/hAnCr/2/

$("document").ready(
function(){
$('#container').highcharts({
        chart:{
            type:'pie',
            height: 300,
            width: 400
              },
        credits:{enabled: false},
        colors:[
            '#5485BC', '#AA8C30', '#5C9384', '#981A37', '#FCB319',     '#86A033', '#614931', '#00526F', '#594266', '#cb6828', '#aaaaab', '#a89375'
            ],
        title:{text: null},
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                showInLegend: true,
                dataLabels: {
                    enabled: false,                        
                    formatter: function() {
                        return this.percentage.toFixed(2) + '%';
                    }
                }                                   
            }
        },
        legend: {
            enabled: true,
            layout: 'vertical',
            align: 'right',
            width: 200,
            verticalAlign: 'middle',
            useHTML: true,
            labelFormatter: function() {
                return '<div style="text-align: left; width:130px;">' + this.name + '</div><div style="width:40px; text-align:right;">' + this.y + '%</div>';
            }
        },
        series: [{
            type: 'pie',
            dataLabels: {

                    },
            data: [
                ['Domestic Equity', 38.5],
                ['International Equity', 26.85],
                ['Other', 15.70],
                ['Cash and Equivalents', 10.48],
                ['Fixed Income', 8.48]
            ]
        }]
    });
});
4

1 回答 1

13

你应该设置 float:left; 对于图例中的两个 div。

http://jsfiddle.net/hAnCr/25/

labelFormatter: function() {
                return '<div style="text-align: left; width:130px;float:left;">' + this.name + '</div><div style="width:40px; float:left;text-align:right;">' + this.y + '%</div>';
于 2013-04-26T08:42:29.340 回答