如何将值传递给highcharts?

时间:2016-05-27 22:01:00

标签: javascript highcharts

我有以下代码,试图获得" this.y" outside highcharts函数用于为数据设置不同的工具提示文本。请帮我解释如何传递y访问值?

var series = [];
var myData = {
    'color': 'url(#defaultYou)',
    'name': 'Me',
    'data': [],
    tooltip: {
        useHTML: true,
        headerFormat: '',
        pointFormat: 'Your current Salary in USD this.y',
        footerFormat: '',
    }
};

var maleData = {
    showInLegend: false,
    'color': 'url(#defaultMale)',
    'name': 'Male',
    'data': [],
    tooltip: {
        useHTML: true,
        headerFormat: '',
        pointFormat: 'Income this.y <br> Experience 3 Year(s)',
        footerFormat: '',
    }
};

var femaleData = {
    showInLegend: false,
    'color': 'url(#defaultFemale)',
    'name': 'Female',
    'data': [],
    tooltip: {
        useHTML: true,
        headerFormat: '',
        pointFormat: 'Income this.y <br> Experience 3 Year(s)',
        footerFormat: '',
    }
};

series = [maleData, femaleData, myData];

drawChart(series, 'My Chart Title');

function drawChart(series, chartTitle) {
    $('#container').highcharts({

        chart: {
            type: 'bubble',
            zoomType: 'xy',
            spacingBottom: 0,
            events: {
                load: function () {

                }
            }
        },

        title: {
            text: chartTitle,
            useHTML: true,
            style: {
                color: '#333333',
                fontSize: '18px',
                textAlign: 'center'
            }
        },

        xAxis: {
            gridLineWidth: 0,
            min: 0,
            max: 20,
            labels: {
                enabled: false
            },
            lineWidth: 0,
            tickWidth: 0
        },

        yAxis: {
            gridLineWidth: 0,
        },

        legend: {
            enabled: true
        },

        series: series

    });

}

1 个答案:

答案 0 :(得分:3)

来自Highcharts的文档:

  

<强> pointFormat:   StringSince 2.2中点的行的HTML   提示。 变量用大括号括起来 .....

长话短说,您应该使用this.y而不是{point.y}http://jsfiddle.net/kadoshms/qgx28yyp/