jqPlot饼图 - 如何捕获图例项目上的点击?

时间:2012-11-14 11:55:22

标签: jquery jqplot

到目前为止,这是故事。

  1. 我已经使饼图切片可以点击,因此用户可以点击转到列出与该切片相关的项目的其他页面。

  2. 对于非常小的切片,用户很难点击它们。因此,我希望饼图旁边的图例具有相同的功能 - 单击图例项,转到URL。

  3. 似乎没有办法挂钩点击图例。我正在寻找像jqplotLegendClick这样的东西。我可以使用HTML A元素作为图例文本,这是一个可接受的解决方案,但是当我点击它时没有任何反应!

  4. 知道怎么处理这个吗?我原本以为这是一种常见的情况。

    这是一个最小的jsfiddle,显示下面建议的解决方案不起作用,以防有人发现问题。 http://jsfiddle.net/Ep4sP/这是js部分。

    $(function ()
    {
    
        var data = [['2012-09-13', 1], ['2012-10-22', 2], ['2012-01-12', 3]];
    
        $.jqplot('ChartDIV', [data],
        {
            seriesDefaults: {
                renderer: jQuery.jqplot.PieRenderer
            },
            legend: { show: true }
        });
    
        $('.jqplot-table-legend-label').each(function(){
            $(this).click(function(){
                alert('you have clicked on the serie : ' + $(this).html());
            });
        });
    
    });
    

1 个答案:

答案 0 :(得分:2)

您可以在图表初始化后添加以下代码:http://jsfiddle.net/WdLnm/272/

$('.jqplot-table-legend-label').each(function(){
    $(this).click(function(){
        alert('you have clicked on the serie : ' + $(this).html());
    });
});

请注意,在最近的版本中,类名为.jqplot-table-legend(使用1.0.8测试)