dc/d3 line chart crashing down to 0 on the y axis after filtering

安稳与你 提交于 2019-11-30 09:47:14

问题


When I apply a dimension filter to a dc.js graph, there are ugly lines where the line plummets towards the y axis.

Is it possible in dc/d3 to not do this, i.e I would expect the graph to more resemble the following;


回答1:


You can call defined directly on the dc created chart.

chart
  .chart((c) ->
    dc.lineChart(c)
      .interpolate('linear')
      .defined((d) ->
        return !isNaN(d.y)
      )
  )

The condition !isNan(d.y) can be anything you like that evaluates to true/false.

Note that the d passed by defined is a d3 object and is worth inspecting.




回答2:


Two possible solutions, depending whether you want the line connected or in sections:

  1. Pre-filter the data so that instead of having groups that sum to zero, there aren't groups there at all. This will connect the points with a line segment over the missing data. https://github.com/dc-js/dc.js/wiki/FAQ#filter-the-data-before-its-charted

  2. Use lineChart.defined to put gaps/breaks in the line where there is no data. https://github.com/dc-js/dc.js/blob/master/web/docs/api-latest.md#definedvalue



来源:https://stackoverflow.com/questions/24413683/dc-d3-line-chart-crashing-down-to-0-on-the-y-axis-after-filtering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!