如何使用dc.js或d3.js为行图添加轴标签 [英] How to add axis labels for row chart using dc.js or d3.js

查看:679
本文介绍了如何使用dc.js或d3.js为行图添加轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于条形图和堆叠图,我们可以使用 .xAxisLabel(X Axis Label) .yAxisLabel )函数添加相应轴的标签。
但是,
有没有办法为行图添加轴标签?

For Bar Chart and Stacked Chart, we can use .xAxisLabel("X Axis Label") and .yAxisLabel("Y Axis Label") functions to add labels for respective axis. But, Is there any way to add axis labels for Row Chart?

推荐答案

这:

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/

Here is a jsfiddle example: http://jsfiddle.net/djmartin_umich/x5qb9/

我希望这有助于!
-DJ

I hope this helps! -DJ

这篇关于如何使用dc.js或d3.js为行图添加轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆