简体   繁体   English

Dc.js 与行图上的 Bootstrap styles 冲突

[英]Dc.js conflicts with Bootstrap styles on rowchart

I'm building a dashboard using dc.js / d3.js / crossfilter / bootstrap but I'm stuck on building a row chart .我正在使用dc.js / d3.js / crossfilter / bootstrap构建一个仪表板,但我一直在构建一个行图

The problem is that all the rows of the chart are rendering with the same length, even when the group is being calculated correctly and their values are distincts (4/3/1) (you can check it doing groupB.all() on terminal).问题是图表的所有行都以相同的长度呈现,即使组被正确计算并且它们的值是不同的(4/3/1)(您可以在终端上执行groupB.all()检查它).

The source of the problem, which I found out after multiple headaches, is that bootstrap's styles overrides rect tags width.问题的根源是引导程序的 styles 覆盖了rect标签宽度,这是我在多次头痛之后发现的。 See the pictures where the problem goes away unchecking the width attribute on the .row>* selector's class.查看图片,取消选中.row>*选择器的 class 上的宽度属性,问题就消失了。

I couldn't solve this.我无法解决这个问题。 I tried writing styles to override it using width: revert , width: auto , width: initial and even tried using jQuery to remove that attribute after render, but cannot get it to work.我尝试编写 styles 以使用width: revertwidth: autowidth: initial覆盖它,甚至尝试使用 jQuery 在渲染后删除该属性,但无法使其工作。 It seems that none of these methods are exactly the same than unchecking the attribute definition on Chrome inspector.似乎这些方法都与取消选中 Chrome 检查器上的属性定义完全相同。

I can't change any library version due it is a large project and has other dashboards already built with this same stack.我无法更改任何库版本,因为它是一个大型项目并且已经使用相同的堆栈构建了其他仪表板。

Here is the jsfiddle with the exact same scenario.这是具有完全相同场景的jsfiddle

在此处输入图像描述

在此处输入图像描述

I am afraid that a fix is only available in a recent version of the library.恐怕只有最新版本的库才有修复

If you can't update the version of the dc.js you are using, you could try removing the conflicting class and provide a different one.如果您无法更新您正在使用的dc.js版本,您可以尝试删除冲突的 class 并提供一个不同的版本。

For example, taking as reference your fiddle, please, try the following:例如,以您的小提琴为参考,请尝试以下操作:

const data = [
    {author: "email1", otherField: "asd1"},
    {author: "email1", otherField: "asd2"},
  {author: "email2", otherField: "asd3"},
  {author: "email1", otherField: "asd4"},
  {author: "email3", otherField: "asd5"},
  {author: "email3", otherField: "asd6"},
  {author: "email3", otherField: "asd7"},
  {author: "email3", otherField: "asd8"},
]
var ndx = crossfilter(data)

var dimAuthor = ndx.dimension(function(d){ return d.author })
var groupB = dimAuthor.group().reduceCount()

var chartB = new dc.RowChart("#chart-b");

chartB
    .height(500)
  .width(600)
  .margins({top: 20, right: 50, bottom: 10, left: 45})
  .dimension(dimAuthor)
  .group(groupB)
  .label(function (d){
    return `${d.key} (${d.value})`;
  })
  .ordering(function(d){ return -d.value; })
  .x(d3.scaleLinear().domain([6,500]))
  .xAxis(d3.axisTop())
  .elasticX(true)

dc.renderAll();

// I copied and pasted the whole javascript fragment, but these lines
// are the only necessary

d3.selectAll(".dc-chart  g.row")
  .classed("row", false)
  .classed("dc-row", true);

You probably still will need to tweak the chart styles, but at least they will have the right width.您可能仍需要调整图表 styles,但至少它们将具有正确的宽度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM