8

所以我可以display:none标签前。下面是 css,但我的 .ct-chart 在图表 ex 的左侧和底部仍然有一些东西。下图。

.ct-labels, .ct-grids {
  display: none;
}

理想情况下,蓝色图表位于白色模块的左侧并位于底部下方,以便与 d​​iv 匹配,绝对定位,并且图表响应开启。我假设空白是从 DOM 中仍然存在的标签创建的?

在此处输入图像描述

我想让图表在左侧和底部显示没有空白。我的.ct-chartCSS看起来像这样。

.ct-chart {
position: absolute;
width: 100%;
left: 0;
top: 0;
height: 100%;
padding: 0;
z-index: -1;
}
4

3 回答 3

28

如果您根本不想有标签,没有网格线并删除所有偏移量和填充,您可以这样做,但它需要相当多的配置:

var chart = new Chartist.Line('.ct-chart', {
  labels: [1, 2, 3, 4],
  series: [
    [1, 4, 2, 5],
    [2, 3, 1, 4]
  ]
}, {
  showPoint: false,
  showLine: false,
  showArea: true,
  fullWidth: true,
  showLabel: false,
  axisX: {
    showGrid: false,
    showLabel: false,
    offset: 0
  },
  axisY: {
    showGrid: false,
    showLabel: false,
    offset: 0
  },
  chartPadding: 0,
  low: 0
});

http://jsbin.com/patela/1/edit?html,css,js,输出

于 2015-04-28T19:00:54.770 回答
0

是的,这些是带有 x 和 y 值偏移的 svg 元素。请参阅此处的示例http://gionkunz.github.io/chartist-js/examples.html <g class="ct-labels"></g> 中的元素都定义了移动它们的 x 和 y 偏移量远离父元素。在图表加载后用 d3 覆盖这些值将非常简单。

于 2015-04-08T19:45:03.030 回答
-1

当我加载图表时,我喜欢检查图表宽度和标签数量,如果需要,我可以显示标签,只显示其他标签,或者根据标签是否适合隐藏所有标签。此代码隐藏标签:

setTimeout(function() {
    $('.ct-chart').find('.ct-labels .ct-horizontal').remove();
}, 100);
于 2015-11-15T00:14:08.903 回答