自定义工具提示名称饼图

时间:2015-05-26 07:53:52

标签: javascript charts highcharts

我正在使用Highcharts饼图,我想为每个点添加自定义后缀。例如,现在我在工具提示格式化程序中有这个:

tooltip : { formatter : function() { return 'Daily KB: <b>'+ this.point.y +'</b>'; } },

显示弹出窗口的方式类似于每个饼图Daily KB: 300。我该如何修改它,以便弹出一个像Daily KB: 700 remaining这样的另一个,另一个将是Daily KB: 300

Highcharts script:
(function($){
    $(this.document).ready(function(){
        //get local time
    Highcharts.setOptions({
            colors: ['#fa604c', '#00CC66']
    });;
        myChart_d = new Highcharts.Chart({

     chart: {
         height:200,
         width:200,
         type: 'pie',
         animation: false,
         renderTo: 'dailychart',
         zoomType: 'x',

           events:  {
            load: function () {
                requestDataLim();

            }
        }

        },
     title: {
        text: 'Daily'
    },
     tooltip : {
                    formatter : function() {
           return 'Daily KB: <b>'+ this.point.y +'</b>';
        }
                },
    //tooltip: {
            //shared:true
        //},
      plotOptions: {
        pie: {
           //   allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: false,

                },
            borderColor: '#A0A0A0',
            innerSize: '40%',

        },
        series:{
           dataLabels: {
               style:{ fontSize: '14px', fontWeight:'bold' },
                enabled: true,
                formatter: function() {
                    return Math.round(this.percentage) + ' %';
                },
                distance: -15,
                color:'black'
            } 
        },
    },
    credits: {
        enabled: false
    },

    series: [{

        name: 'DailyKB',
        data: 
            [<?php echo join(',',$d); 
                  echo ',';
                  echo join (',',$dl);?>]




    }],
exporting: {
buttons: {
    printButton: {
        enabled: false
    },
    exportButton: {
        enabled: false
    }    
}

}

});

我通过ajax和JSON获取数据,目前类似于[300, 700]

1 个答案:

答案 0 :(得分:0)

如何将数据格式更改为对象数组?例如:

 [{y: 300, suffix: ""}, {y: 700, suffix: " remaining" }]

然后在工具提示中添加suffix信息:

return 'Daily KB: <b>'+ this.point.y +'</b>' + this.point.options.suffix;