【问题标题】:dimple.js or d3.js - Draw chart's legend at bottom of svg elementdimple.js 或 d3.js - 在 svg 元素底部绘制图表的图例
【发布时间】:2014-09-06 01:17:28
【问题描述】:

我试图弄清楚如何让我的图例出现在图表的底部,但没有运气。 在下面的代码中,由于我的图表高度为 600,我想我可以简单地为 Y 坐标添加 600 的偏移量,这样就可以了。但是不起作用。

var svg = dimple.newSvg("#chart", 800, 600);
...
chart.addLegend(0, 600 + 40, 200, 10, "left");

有人知道如何使用dimple.js 或d3.js 解决这个问题吗?如果我不必对这些值进行硬编码,而是可以执行以下操作,那就太好了:

chart.addLegend(0, d3.select("#chart").height + 40, 200, 10, "left");

这里是 dimple.js 的 addLegend 的文档: https://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.chart#addLegend

【问题讨论】:

    标签: d3.js visualization rickshaw dimple.js


    【解决方案1】:

    你的代码应该没问题。

    请检查 js fiddle(http://jsfiddle.net/ch2187dd/)

    var svg = dimple.newSvg("#chartContainer", 590, 540);
    var myChart = new dimple.chart(svg, data);
    myChart.setBounds(90, 35, 480, 325)
    myChart.addCategoryAxis("x", ["date"]);
    myChart.addCategoryAxis("y", "close");
    myChart.addSeries("Price Tier", dimple.plot.bubble);
    myChart.addLegend(90, 480, 330, 20, "left");
    myChart.draw();
    

    【讨论】:

    • 谢谢。我想我错过了 setBounds。我猜 svg 维度是整个“画布”区域,而 setBounds 方法将图表限制在 svg 画布内的一个区域,留出空间来绘制其他形状/元素?
    猜你喜欢
    • 1970-01-01
    • 2013-07-07
    • 1970-01-01
    • 1970-01-01
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    相关资源
    最近更新 更多