jquery 在迷你图中获取 x 值

jquery getting x values in sparkline

我是 jQuery 的新手,正在尝试制作迷你图。我想要的是,当鼠标指向图中的一个点时,x 值和 y 值 都应该被看到。目前,只有 y 值可见。

<script>
    $(document).ready(function () {
        $("#sparkline").sparkline([1, 4, 6, 6, 8, 5, 3, 5], {
            type: 'line',
            height: '200',
            width: '240',
            barWidth: 20,
            barSpacing: 10,
            barColor: '#615c5a',
            fillColor:"white"
        });
    });
</script>

你可以试试这个:

$('#sparkline').sparkline([1, 4, 6, 6, 8, 5, 3, 5], {
        type: 'line',
        height: '200',
        width: '240',
        barWidth: 20,
        barSpacing: 10,
        barColor: '#615c5a',
        fillColor:"white",          
        tooltipFormatter: function (sparkline, options, fields) {
         return "x: " + fields.x + " y: " + fields.y + "";
        }
 });

Demo