gpt4 book ai didi

javascript - 图表中的网格线,本例中如何获取

转载 作者:太空宇宙 更新时间:2023-11-04 13:47:26 25 4
gpt4 key购买 nike

如何获取下图中的网格线?我一直在尝试使用 d3noobs d3 提示和技巧来获取网格线。但是这段代码不起作用

       .grid.tick {
stroke: lightgrey;
opacity: 0.7;
}
.grid path {
stroke-width: 0;
}



<!DOCTYPE html>
<html>
<head>
<title>The d3 test</title>
<style> \\ css
.chart {

}

.main text {
font: 10px sans-serif;
}

.axis line, .axis path {
shape-rendering: crispEdges;
stroke: black;
fill: none;
}

circle {
fill: steelblue;
}



</style>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.v2.js">

</script>
</head>
<body>\\ script
<div class='content'>
<!-- /the chart goes here -->
</div>
<script type="text/javascript" src="scatterchart.js"></script>

</body>
</html>

和散点图.js

     var data = [[2,2], [2,5], [6,6], [6,7],[25,25]];

var margin = {top: 20, right: 15, bottom: 60, left: 60}
, width = 960 - margin.left - margin.right
, height = 500 - margin.top - margin.bottom;

var x = d3.scale.linear()
.domain([0, d3.max(data, function(d) { return d[0]; })])
.range([ 0, width ]);

var y = d3.scale.linear()
.domain([0, d3.max(data, function(d) { return d[1]; })])
.range([ height, 0 ]);

var chart = d3.select('body')
.append('svg:svg')
.attr('width', width + margin.right + margin.left)
.attr('height', height + margin.top + margin.bottom)
.attr('class', 'chart')

var main = chart.append('g')
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')')
.attr('width', width)
.attr('height', height)
.attr('class', 'main')

// draw the x axis
var xAxis = d3.svg.axis()
.scale(x)
.orient('bottom');

main.append('g')
.attr('transform', 'translate(0,' + height + ')')
.attr('class', 'main axis date')
.call(xAxis);

// draw the y axis
var yAxis = d3.svg.axis()
.scale(y)
.orient('left');

main.append('g')
.attr('transform', 'translate(0,0)')
.attr('class', 'main axis date')
.call(yAxis);




var g = main.append("svg:g");

g.selectAll("scatter-dots")\\dots
.data(data)
.enter().append("svg:circle")
.attr("cx", function (d,i) { return x(d[0]); } )\\x pos
.attr("cy", function (d) { return y(d[1]); } )\\ y pos
.attr("r", 8); \\ radius

那么如何获取图表中的网格线呢?

最佳答案

您没有为网格线放置必要的代码。这是 FIDDLE与必要的代码。检查代码中的最后几行,从以下内容开始:

main.append("g")
.attr("class", "grid")
.attr("transform", "translate(0," + height + ")")
.call(make_x_axis()
.tickSize(-height, 0, 0)
.tickFormat(""));

...

关于javascript - 图表中的网格线,本例中如何获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22434147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com