【发布时间】: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