1

我正在尝试将我的标签格式化为百分比。我已经尝试查看 Chartist.js 的文档并将其转换为 CoffeeScript,问题是事情对我来说不是很清楚,因为我们使用的是 Angular 和angular-chartist模块。这是一个相当微不足道的作品,我不能要求我的联合创始人花时间,因为我们的项目中有许多更大的作品在发挥作用,但我想了解我的不足之处。

该图表使用 chartist 指令显示(我猜它是其中的一部分angular-chartist):

<chartist class="ct-chart" chartist-data="typeCounts" chartist-chart-type="Bar" chartist-responsive-options="typeCounts.barResponsiveOptions"></chartist>

这是我尝试获取选项的咖啡脚本(请注意,标签和系列属性工作正常;但图表元素没有获取该barResponsiveOptions属性(因此console.log调试行没有触发):

  # Organize return data into labels and series for Chartist
  typeCounts = ResultService.getTypeCounts()
  $scope.typeCounts.labels = Object.keys(typeCounts)
  $scope.typeCounts.series = [typeCounts[type] for type in Object.keys(typeCounts)]
  $scope.typeCounts.barResponsiveOptions = [
    axisY:
      labelInterpolationFnc: (value) ->
        console.log("Firing barResponsiveOptions")
        Math.round(value * 100) + '%'
  ]

现在图表显示 y 轴上的数据点为 1 的分数(例如 0.0 -> 1.0)。

4

1 回答 1

1

您应该将该chartist-chart-options属性用于常规选项,并且chartist-responsive-options如果您不使用此处解释的响应式选项https://gionkunz.github.io/chartist-js/getting-started.html#responsive-sugar-topping

干杯

于 2015-12-17T14:26:17.747 回答