1

私は Highcharts JavaScript ライブラリを使用していくつかの float 値を視覚化し、それを php 経由で js コードにフィードしています。次の図でわかるように、各ポイントのマウスオーバーで、軸の値に対応する 2 つの値とテキスト "text: undefined" が表示されます。現在の可視化

私の質問は: 散布図の各ポイントに異なるテキストを表示する方法はありますか? 各ポイントに対応するテキストがありますが、それを表示する方法が見つかりません。

私の JavaScript/php コードは次のとおりです。

<script type="text/javascript">
    $(function () {
var chart;
$(document).ready(function() {
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'scatter',
            zoomType: 'xy'},
        title: {
            text: 'Average 24hrs Sentiment for <?php echo $channel?> by Gender '
        },
        subtitle: {
            text: 'Source: '
        },
        xAxis: {
            title: {
                enabled: true,
                text: 'Hours ([0-24h].[0-60mins])'
            },
            startOnTick: true,
            endOnTick: true,
            showLastLabel: true
        },
        yAxis: {
            title: {
                text: 'Sentiment (N. Bayes) %'
            }
        },
        tooltip: {
            formatter: function() {
                    return ''+
                    this.x +' hrs, '+ this.y +' sentiment, text: ';
            }
        },
        legend: {
            layout: 'vertical',
            align: 'left',
            verticalAlign: 'top',
            x: 24,
            y: 1,
            floating: true,
            backgroundColor: '#FFFFFF',
            borderWidth: 1
        },
        plotOptions: {
            scatter: {
                marker: {
                    radius: 5,
                    states: {
                        hover: {
                            enabled: true,
                            lineColor: 'rgb(100,100,100)'
                        }
                    }
                },
                states: {
                    hover: {
                        marker: {
                            enabled: false
                        }
                    }
                }
            }
        },
        series: [{
            name: 'Female',
            color: 'rgba(223, 83, 83, .5)',
            data: [
            <?php 

            for($j=0;$j<$i1;$j++)
            {
                if($females[$j]['Hour'][0] == "0")
                {
                    echo '['.$females[$j]['Hour'][1].'.'.$females[$j]['Min'].','.$females[$j]['Sent'].'"]';
                }
                else
                    echo '['.$females[$j]['Hour'].'.'.$females[$j]['Min'].','.$females[$j]['Sent'].'"]';

                if(($j+1)!=$i1)
                {
                    echo ",";
                }
            }
        ?>
        ]}, 
            {
            name: 'Male',
            color: 'rgba(119, 152, 191, .5)',
            data: [
            <?php 

            for($j=0;$j<$i2;$j++)
            {
                if($males[$j]['Hour'][0] == "0")
                {
                    echo '['.$males[$j]['Hour'][1].'.'.$males[$j]['Min'].','.$males[$j]['Sent'].',"'.$males[$j]['Text'].'"]';
                }
                else
                    echo '['.$males[$j]['Hour'].'.'.$males[$j]['Min'].','.$males[$j]['Sent'].',"'.$males[$j]['Text'].'"]';

                if(($j+1)!=$i2)
                {
                    echo ",";
                }
            }
            ?>
            ]}]
    });
});    

});

ありがとうございました。

4

2 に答える 2

2

テキストが各ポイントに固有である場合は、x と y 以外の値を渡すことができます。次のでは、locked、unlocked、および potential の 3 つの値を渡します。次に、ツールチップ フォーマッタでそれらにアクセスするには、this.point.locked

于 2012-08-09T15:59:09.627 に答える
1
 this.x +' hrs, '+ this.y +' sentiment, text: ';

私の提案があなたの問題を解決するかどうかを確認するために、このコード行にテキストを設定してみてください:

 this.x +' hrs, '+ this.y +' sentiment, text: '+this.x;

そして、(this.x) の値が "undefined" ではなく表示されるかどうかを確認します。

于 2012-08-09T15:52:25.203 に答える