简体   繁体   English

Highcharts工具提示不显示相应的文本值,而是显示“未定义”

[英]Highcharts tooltip not displaying corrosponding text value, instead displaying 'undefined'

I have a list of text values with their corresponding score values (value X and value y). 我有一个文本值及其对应得分值(值X和值y)的列表。 I am able to plot a dot at the intersection of value x and value y. 我能够在值x和值y的交点处绘制一个点。 Hovering over the dot displays the location value of the dot on x,y coordinates but for the corresponding text value it is displaying unidentified. 将鼠标悬停在点上会在x,y坐标上显示点的位置值,但是对于相应的文本值来说,该位置值未显示。

<script>

    var array = @Html.Raw(Json.Encode(ViewBag.Items3DList));
    var practicalityscore = [];
    for(var i in array){
        var serie = new Array(array[i].YAxis, array[i].AvgIPA, array[i].Title);
        practicalityscore.push(serie);
    }

    $(function () {

        var chart = new Highcharts.Chart({
            chart: {
                renderTo: 'practicalityscore',
                zoomType: 'xy',
                defaultSeriesType:'scatter',
                borderWidth:1,
                borderColor:'#fff',
                marginLeft:50,
                marginRight:50,
                backgroundColor:'#fff',
                plotBackgroundColor:'#fff',

            },
            credits:{enabled:false},
            title:{
                text:'Most Practical Ideas',
                align: 'left',

            },
            legend:{
                enabled:false
            },
            tooltip:{
                crosshairs: [{
                    enabled:true,
                    width:1,
                    color:'rgba(238,46,47,.25)'
                },{
                    enabled:true,
                    width:1,
                    color:'rgba(238,46,47,.25)'
                }],

                formatter: function(){
                    return '<span><b>Practicality</b>: '+ Highcharts.numberFormat(this.x,0) + '<br/><span><b>Avg IPA</b>: '+ Highcharts.numberFormat(this.y,0) + '<br/><span><b>Idea</b>: '+ this.point.name;
                }
            },
            plotOptions: {
                series: {
                    color:'#0093dd',
                    marker: {
                        fillOpacity:1,
                        radius:7,
                        lineWidth:.5,
                        lineColor:'#fff',
                    },

                }
            },
            xAxis:{
                title:{
                    text:'Practicality Score'
                },
                min:0,
                max:10,
                tickInterval:1,
                tickLength:0,
                minorTickLength:0,
                gridLineWidth:0,
                showLastLabel:true,
                showFirstLabel:false,
                lineColor:'#fff',
                lineWidth:0
            },
            yAxis:{
                title:{
                    text:'AvgIPA',
                    rotation:-90,
                    margin:10,
                },
                min:0,
                max:10,
                tickInterval:1,
                tickLength:0,
                minorTickLength:0,
                lineColor:'#fff',
                lineWidth:0
            },
            series: [{
                color:'rgba(238,46,47,.5)',
                data: practicalityscore,

            }]
        }, function(chart) { // on complete

            var width = chart.plotBox.width / 2.0;
            var height = chart.plotBox.height / 2.0 + 1;

            chart.renderer.rect(chart.plotBox.x,
                                chart.plotBox.y, width, height, 1)
                .attr({
                    fill: '#fff',
                    'stroke-width': 4,
                    stroke: '#fff',
                    zIndex: 1
                })
                .add();

            chart.renderer.rect(chart.plotBox.x + width,
                                   chart.plotBox.y, width, height, 1)
                   .attr({
                       fill: '#fff',
                       'stroke-width': 4,
                       stroke: '#fff',
                       zIndex: 1
                   })
                   .add();

            chart.renderer.rect(chart.plotBox.x,
                                    chart.plotBox.y + height, width, height, 1)
                    .attr({
                        fill: '#fff',
                        'stroke-width': 4,
                        stroke: '#fff',
                        zIndex: 1
                    })
                    .add();

            chart.renderer.rect(chart.plotBox.x + width,
                                    chart.plotBox.y + height, width, height, 1)
                    .attr({
                        fill: '#fff',
                        'stroke-width': 4,
                        stroke: '#fff',
                        zIndex: 1
                    })
                    .add();

        });
    });
</script>

Here is the json representation of my array object which i received from my server side code. 这是我从服务器端代码接收到的数组对象的json表示形式。

array[1]
object{
AvgIPA:7, IdeaId:17989, Likes:3, Status:2, StatusString:"Published", Title:"Spread the word", UserFullName:"Anurag Acharya", XAxis:9, YAxis:5, ZAxis:7}

Now i send only the relevant data to my series from practicalityscore array. 现在,我仅将相关数据从Practicalscore数组发送到我的系列中。 Here is the representation of that data. 这是该数据的表示。

practicalityscore [1]
[5, 7, "Spread the word"]

Here is the screenshot of how browser is displaying the data on chart 这是浏览器如何在图表上显示数据的屏幕截图

Instead of undefined, "Spread the word" should get displayed. 而不是未定义,应该显示“扩展单词”。

You may try to modify your formatter as following , change this.point.name to this.point.series.name 您可以尝试如下修改格式化程序,将this.point.name更改为this.point.series.name

function(){
    return '<span><b>Practicality</b>: '+
        Highcharts.numberFormat(this.x,0) + 
        '<br/><span><b>Avg IPA</b>: '+ 
        Highcharts.numberFormat(this.y,0) + 
        '<br/><span><b>Idea</b>: '+  this.point.series.name;
}

Not sure if I understand your objective correctly, hope this help 不确定我是否正确理解了您的目标,希望有帮助

I tried to create a similar jsfiddle example base on my understand 我试图根据我的理解创建一个类似的jsfiddle示例

http://jsfiddle.net/unshz5uu/ http://jsfiddle.net/unshz5uu/

You need to replace your array for point with object. 您需要将对象的数组替换为object。 It should be {x: 5, y:7, name: "Spread the word"}. 它应该是{x:5,y:7,名称:“扩展单词”}。 Then in formatter refer to this.point.options.name 然后在格式化程序中参考this.point.options.name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM