感谢 Zoe,我修改了我的代码以响应在 Windows 调整大小时重绘。
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 xAxis = new Plottable.Axes.Category(xScale, "bottom");
var yAxis = new Plottable.Axes.Numeric(yScale, "left");
var plot = new Plottable.Plots.Bar()
.addDataset(new Plottable.Dataset(data))
.x(function(d) { return d.x; }, xScale)
.y(function(d) { return d.y; }, yScale);
var chart = new Plottable.Components.Table([
[yAxis, plotBar],
[null, xAxis]
]);
chart.renderTo("svg#svgSample");
window.addEventListener("resize", function () {
plot.redraw();
});
如您所见,我什至不需要担心在 css 中设置宽度和高度。我认为 Plottable 在调用 plot.redraw() 时会处理它!
谢谢佐伊!