1 回答
TA贡献2003条经验 获得超2个赞
您在谈论<svg>元素,但这些只是用于绘制图表的占位符。
您需要做的主要事情是读取要绘制的数据并将其存储在全局变量中,或者将其传递给绘制单个图表的函数。
function drawLineChart(data) {
var lineChart = d3.body.append('svg').classed('line-chart', true);
// draw a line chart here
return lineChart;
}
function drawBarChart(data) {
var barChart = d3.body.append('svg').classed('bar-chart', true);
// draw a bar chart here
return barChart;
}
function registerEventListeners(charts) {
// given an array of charts, register `mouseenter`, `mouseleave`,
// or `click` event listeners for each one, and, within their handlers,
// also change the other charts you've passed.
}
d3.csv('data', function(data, error) {
// read the data and call the other functions with it
var charts = [
drawLineChart(data),
drawBarChart(data),
];
registerEventListeners(charts);
});
添加回答
举报