我希望消除下拉列表依赖项。 如何在不破坏代码的情况下从html中删除.change函数。 我希望图表加载时没有从下拉列表中选择,我不想下拉,但html与此相关。 这是我获取代码的地方: https://github.com/jakezatecky/d3-funnel
谢谢,
<!DOCTYPE html>
<html lang="en"
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>D3 Funnel</title>
<link rel="stylesheet" href="httpmaxcdn.bootstrapcdn.combootstrap3.3.4cssbootstrap.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>D3 Funnel</h1>
<div class="example">
<form class="form-inline">
<select class="form-control" id="picker">
<option value="basic">No options</option>
</select>
</form>
<!-- Funnel container -->
<div id="funnel"></div>
</div>
</div>
<!-- Required D3 library -->
<script src="httpcdnjs.cloudflare.comajaxlibsd33.5.5d3.js"></script>
<!-- D3Funnel source file -->
<script src="d3-funnel.js"></script>
<!-- Just for the example -->
<script src="httpcode.jquery.comjquery-2.1.4.js"></script>
<script>
$(function() {
$('#picker').change(function() {
var index = $(this).val();
var data = {
normal: [
['Applicants', 100],
['Pre-screened', 400],
['Interviewed', 250],
['Hired', 150],
['Fired', 205]
],
};
var options = {
basic: [data.normal, {
fillType: 'gradient',
dynamicArea: true
}],
};
var chart = new D3Funnel('#funnel');
chart.draw(options[index][0], options[index][1]);
});
</script>
</body>
</html>
答案 0 :(得分:2)
用以下块替换脚本块
var index = 'basic';
var data = {
normal: [
['Applicants', 100],
['Pre-screened', 400],
['Interviewed', 250],
['Hired', 150],
['Fired', 205]
],
};
var options = {
basic: [data.normal, {
fillType: 'gradient',
dynamicArea: true
}],
};
var chart = new D3Funnel('#funnel');
chart.draw(options[index][0], options[index][1]);
你可以删除对jQuery的引用。