作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Plottable.js 在我的页面上绘制图表。我想在调整窗口大小时调整图表的大小。
我尝试通过 css(以及 svg 宽度和高度属性)设置大小,但没有成功。
这是我尝试通过 svg 属性进行设置:
$('#svgSample').attr('width', w);
$('#svgSample').attr('height', h);
这是我通过 css 设置的尝试:
$('#svgSample').css({
'width': w + 'px',
'height': h + 'px'
});
有什么想法吗?
谢谢
最佳答案
我相信您需要做的就是在设置 svg 属性后调用 Plot.redraw()
这是一个例子:
window.onload = function() {
var data = [
{ x: 1, y: 1 },
{ x: 2, y: 1 },
{ x: 3, y: 2 },
{ x: 4, y: 3 },
{ x: 5, y: 5 },
{ x: 6, y: 8 }
];
var xScale = new Plottable.Scales.Linear();
var yScale = new Plottable.Scales.Linear();
var plot = new Plottable.Plots.Scatter()
.addDataset(new Plottable.Dataset(data))
.x(function(d) { return d.x; }, xScale)
.y(function(d) { return d.y; }, yScale);
plot.renderTo("#chart");
$('#chart').attr('width', 500);
$('#chart').attr('height', 400);
plot.redraw();
}
</style> <link rel="stylesheet" type="text/css" href="https://rawgithub.com/palantir/plottable/develop/plottable.css"> <style type="text/css">
body { background-color: #AAA; }
svg { background-color: #FFF; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="https://rawgithub.com/palantir/plottable/develop/plottable.js"></script>
<svg id="chart" width="100" height="100"></svg>
关于javascript - 如何在 Plottable.js 中调整图表大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33141679/
我是一名优秀的程序员,十分优秀!