javascript - 如何通过css在dc.js中设置饼图的宽度

标签 javascript css width media-queries dc.js

我想为不同的分辨率设置不同的 dc.js 饼图宽度;为此,我想通过 css 设置饼图的宽度,以便我可以为不同的分辨率应用媒体查询。 请提供通过 css 设置 dc.js 饼图宽度的解决方案。

icd9Pie /* dc.pieChart('#gain-loss-chart', 'chartGroup') */
        // (_optional_) define chart width, `default = 200`

          .width(180) // (optional) define chart height, `default = 200`
          .height(160)

        // Define pie radius
        .radius(80)
        // Set dimension
        .dimension(icd9Dimension)
        // Set group
        .group(icd9Group)
        // (_optional_) by default pie chart will use `group.key` as

        // its label but you can overwrite it with a closure.
        .label(function(d) {
            return d.key;
        }).renderLabel(true)
        /

//新代码

 icd9Pie /* dc.pieChart('#gain-loss-chart', 'chartGroup') */
        // (_optional_) define chart width, `default = 200`

          .minWidth(180) // (optional) define chart height, `default = 200`
          .minHeight(160)

        // Define pie radius
        .radius(80)
        // Set dimension
        .dimension(icd9Dimension)
        // Set group
        .group(icd9Group)
        // (_optional_) by default pie chart will use `group.key` as

        // its label but you can overwrite it with a closure.
        .label(function(d) {
            return d.key;
        }).renderLabel(true)
        /

最佳答案

我认为您可能刚刚遇到了最小尺寸参数,minWidthminHeight - 默认情况下它们是 200。

Docs for minWidth and minHeight

媒体查询没有像您上面指定的那样工作,我不得不添加大括号。这对我完全有用:

@media (max-width: 1280px) {
  #test { width: 180px !important; height: 160px !important; }
}

并设置 minWidthminHeight 以允许它们低于 200:

chart.minWidth(100)
   .minHeight(100)

关于javascript - 如何通过css在dc.js中设置饼图的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33993285/

相关文章:

javascript - 谷歌通用分析 : Send additional parameters in event tracking

Jquery 插件 : backstretch not working as it should

css - Azure媒体播放器: make it fix the width and hide the play overlay?

android - 将一个 TextView 彼此对齐 - Android

CSS:当位置是静态或相对时,我可以将宽度设置为屏幕大小吗?

javascript - jQuery ajax 未捕获类型错误 : Illegal invocation

javascript - 将绝对定位元素限制为容器宽度

html - 如果 parent 的宽度以百分比表示,则使表格宽度为 100%

javascript - 如何检查 if 语句的条件以查看其是否正常工作?

css - 屏幕尺寸和浏览器尺寸的关系