登录

javascript - Highcharts 这么样设置提示里面的内容呢?

比如说我像设置这里的内容,这么样才是设置成跟他一模一样呢!

# JavaScript
高洛峰 高洛峰 2566 天前 227 次浏览

全部回复(2) 我要回复

  • 伊谢尔伦

    伊谢尔伦2017-04-11 13:21:13

    var obj={web:'22',iphone:'30'}; //从后台取出数据,转为object对象
    $(function () {

    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: ''
        },
        tooltip: {
            formatter: function() {
                //tooltip:设置hover时弹出内容,obj[this.point.name] 后台数据
                return '<b>'+ this.series.name +'</b>: '+'<b>'+ this.point.name +'</b><br>'+'<b>'+ '登陆次数' +'</b>: '+'<b>'+obj[this.point.name]+'</b>'
            }
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: '用户终端类型',
            data: [
                ['iphone',   26.67],
                ['web',   73.33]
            ]
        }]
    });

    });

    回复
    0
  • 阿神

    阿神2017-04-11 13:21:13

    highchart提示使用tooltip,饼图并不需要数据是百分比的数,data里面放入个数,饼图会根据数据自动算比例

    回复
    0
  • 取消 回复 发送