【问题标题】:How to add axis labels for row chart using dc.js or d3.js如何使用 dc.js 或 d3.js 为行图添加轴标签
【发布时间】:2014-01-14 13:07:05
【问题描述】:

对于条形图和堆积图,我们可以使用.xAxisLabel("X Axis Label").yAxisLabel("Y Axis Label") 函数为各个轴添加标签。 但, 有什么方法可以为行图添加轴标签吗?

【问题讨论】:

    标签: charts d3.js row axis-labels dc.js


    【解决方案1】:

    试试这样的:

    dc.renderAll();
    
    function AddXAxis(chartToUpdate, displayText)
    {
        chartToUpdate.svg()
                    .append("text")
                    .attr("class", "x-axis-label")
                    .attr("text-anchor", "middle")
                    .attr("x", chartToUpdate.width()/2)
                    .attr("y", chartToUpdate.height()-3.5)
                    .text(displayText);
    }
    AddXAxis(chart1, "This is the x-axis!");
    

    这是一个 jsfiddle 示例:http://jsfiddle.net/djmartin_umich/x5qb9/

    我希望这会有所帮助! -DJ

    【讨论】:

    • 你知道没有jQuery的解决方案吗?
    • tks. 为 y 轴添加标签需要进行哪些更改?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多