【问题标题】:after making bar chart inside SVG using D3 , it is not fitting the entire SVG使用 D3 在 SVG 内制作条形图后,它不适合整个 SVG
【发布时间】:2020-11-25 21:35:53
【问题描述】:

我在 svg 中绘制标签并在内部添加适合数据中特定 (x,y) 的倍数(使用 d3.js lib) svg 在滑块上,(当我检查 svg 元素时没问题,它很合适) 但问题是元素不合适,虽然我可以看到宽度和高度:检查时 100%。 证明

我的代码是:

private createSvg(): void {
    if (this.svg) {
        return;
    }
    this.svg = d3.select("figure#histogram")
        .classed("svg-container", true)
        .append("svg")
        .attr("width", '100%')
        .attr("height", '100%')
        .attr("preserveAspectRatio", "xMinYMin meet")
        .attr("viewBox", "0 0 600 400")
        .classed("svg-content-responsive", true)
        .append("g")
        .attr("width", '100%')
        .attr("height", '100%')
}

有什么帮助吗?

【问题讨论】:

    标签: javascript css angular d3.js svg


    【解决方案1】:

    解决方案: 你应该用这条线来调整你的图表:

    attr("viewBox", "0 0 600 400")
    

    还要注意您为 xAxis 提供的范围,它应该包含适当的值!

    【讨论】:

      猜你喜欢
      • 2019-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-06
      • 1970-01-01
      • 2020-01-19
      • 2018-06-13
      相关资源
      最近更新 更多