【问题标题】:Pie chart click issue - click not detected饼图点击问题 - 未检测到点击
【发布时间】:2013-07-17 05:14:56
【问题描述】:

我一直在尝试创建一个图表来显示世界不同地区发生的事件。所以我基本上选择了两个图表的组合 1) d3 google graph (http://bl.ocks.org/mbostock/899711) 通过地图和 jquery flot 饼图 (http://people.iola.dk/olau/flot/examples/pie.html) 显示区域来映射事件。我已将所有相应的纬度经度值存储到一个数组中,并根据这些值附加地图上的标记。所以基本上我将在<foriegnobject> 的帮助下在相应的标记上创建一个xhtml:div 空间,一旦创建了这些div,我将为每个对应的div 元素添加饼图。所以图表创建成功,饼图的“plotclick”功能,捕捉饼图的点击。在所有饼图中都没有检测到该点击功能。在大多数饼图中,点击切片,会调用相应的点击函​​数。悬停也一样。

问题仅存在于 Firefox 中,并且我使用的是最新版本的 22.0 的 Firefox。该图在 Chrome 中运行良好..

我添加了图表的屏幕截图。 这是一个已知问题还是与创建图表的方法有关?

  // EDIT : (Code Added)

 //google map api options
 var map = new google.maps.Map(d3.select("#mapsss").node(), {
    zoom: 2,
   panControl: true,
   panControlOptions: {
       position: google.maps.ControlPosition.TOP_RIGHT
   },
   zoomControl: false,
    mapTypeControl: false,
           draggable: false,
           scaleControl: false,
           scrollwheel: false,
           streetViewControl: false,
           center: new google.maps.LatLng(37.76487, 0),
           mapTypeId: google.maps.MapTypeId.ROADMAP
});



//create an overlay.
var overlay = new google.maps.OverlayView();

// Add the container when the overlay is added to the map.
overlay.onAdd = function () {
    layer = d3.select(this.getPanes().overlayMouseTarget)
        .append("div")
        .attr("class", "stations");

    // Draw each marker as a separate SVG element.
    // We could use a single SVG, but what size would it have?
    overlay.draw = function () {
        projection = this.getProjection(),
        padding = 10;

        //mapData hasinput details
        var marker = layer.selectAll("svg")
            .data(d3.entries(mapData))
            .each(transform) // update existing markers
        .enter().append("svg:svg")
            .each(transform)
            .attr("class", "marker").attr("id", function (d) {
                return "marker_" + d.key;
            });
        //creating canvas for pie chart
        marker.append('foreignObject')
            .attr('width', '100%')
            .attr('height', '100%').style("background-color", "#000000").append('xhtml:div').attr("class", "pieCanvas").attr("id", function (d) {
                return "canvas_" + d.key.split(" ").join("_");
            }).style('height', '50px').style('width', '50px');

//creating pie chart on each canvas.. key holds the name of each canvas
$.plot($("#canvas_" + key.split(" ").join("_")), pieChartData[key], {
        series: {
            pie: {
                show: true,
                radius: 1,
                innerRadius: 0.3,
                tilt: 0.5,
                label: false,
                stroke: {
                    color: '#ffffff',
                    width: 2.0
                }
            },
        },
        grid: {
            hoverable: true,
            clickable: true
        },
        legend: {
            show: false
        }
    });
}


 //click function
  $(document).on("plotclick", "div.pieCanvas", pieChartClick);

【问题讨论】:

  • 您使用的是什么版本的 Flot?您链接到 iola.dk 上的旧示例页面;您是否尝试过 www.flotcharts.org 的新版本?顺便说一句,很好的可视化!
  • 感谢@DNS!我正在使用从 flotwebsite 本身获得的最新 flot-0.8.1..
  • 你的代码是什么样的?
  • 如果没有看到当前无法正常工作的最小示例,很难回答这个问题......
  • @geocodezip 我添加了一个示例代码来展示工作原理..

标签: javascript jquery google-maps-api-3 d3.js flot


【解决方案1】:

我真的不明白你为什么要使用两个不同的图形库? D3 适用于 svg 元素,而 flot 适用于 canvas 元素。使用 d3 进行交互要容易得多,因为 d3 将 svg 元素附加到 DOM。然后,您可以将所有事件直接绑定到这些元素(请参阅https://github.com/mbostock/d3/wiki/Selections#wiki-on)。

另外,here 是使用 d3 制作饼图的示例。

【讨论】:

    【解决方案2】:

    我可以想到浏览器不注册点击事件的两个原因。

    1 - 事件没有正确绑定

    2 - 点击目标位于不可见层下方,防止浏览器听到点击。一些浏览器对此很宽容,Firefox 似乎在很多方面都相当严格。

    您可以使用网络开发工具中的 FF 3D 视图来查看您的饼图上是否有图层正在渲染。您可以尝试更改饼图的 z-index 来缓解这种情况。

    【讨论】:

      【解决方案3】:

      我不喜欢情节。在我的开发中,浏览器之间反复不兼容,我发现最好的选择是使用另一个库,我使用jplot 多浏览器兼容性更好,IE 6。

      在官方论坛,这个topic有未解答的问题

      【讨论】:

        猜你喜欢
        • 2011-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-15
        • 1970-01-01
        • 2021-01-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多