Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Chartjs-图形值类型浮点_Javascript_Angularjs_Charts - Fatal编程技术网

Javascript Chartjs-图形值类型浮点

Javascript Chartjs-图形值类型浮点,javascript,angularjs,charts,Javascript,Angularjs,Charts,我有两个Chartjs的图,我需要两个图的值都有断开的值,例如(20,15) 按照图形代码进行操作: vm.chart = () => { vm.labels = ["D1", "VC1", "Internacional", "À cobrar", "0300", "Gratuita", "Locais"]; vm.colors = [ '#f36e20', '#8aca7b', '#0bc4df', '#272343', '#389223', '#f1a8

我有两个Chartjs的图,我需要两个图的值都有断开的值,例如(20,15)

按照图形代码进行操作:

vm.chart = () => {
        vm.labels = ["D1", "VC1", "Internacional", "À cobrar", "0300", "Gratuita", "Locais"];
        vm.colors = [ '#f36e20', '#8aca7b', '#0bc4df', '#272343', '#389223', '#f1a80a', '#1e75eb'];
        vm.data = [10, 10, 20, 10, 10, 10, 30];
        vm.options = {
          data: [

            ]
        }
    }
html:

html:

  <canvas class="chart chart-bar" height="250px" 
          chart-data="vm.data_gasto" 
          chart-colors="vm.data_colors" 
          chart-labels="vm.data_labels" 
          chart-options="vm.data_options" 
          ng-init="vm.chart_gasto()">
  </canvas>

除了“断开”的数字外,它们旁边是否存在%值的可能性

有人曾经做过类似的事情吗?

基于:

工具提示标签配置嵌套在工具提示下方 使用回调键进行配置。工具提示包含以下内容 用于提供文本的回调。对于所有功能,“这”将是 从图表创建的工具提示对象。工具提示构造函数

使用相同的参数调用所有函数:工具提示项和 传递到图表的数据对象。所有函数都必须返回 字符串或字符串数组。字符串数组被视为 多行文本

在你的情况下,如果我没有弄错的话,这适用于这样的事情:

  vm.options = {
    tooltips: {
      callbacks: {
        label: (tooltipItem, chart) => {
          const realValue = chart.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]
          const customValue = realValue.toFixed(2).replace(".", ",") + '%';
          const label = chart.labels[tooltipItem.index] + ':';
          return label + customValue;
        }
      }
    }
  }

这里有一个.

值得为您的问题提供任何plunker/Fiddle/Codepen。像这样的值,我有固定值,因为我不能用小数输入值。vm.data的值是固定值,只需要将值放在小数位,例如:10.25、10、20、10、10、10.50、30,但它不接受字符串
  <canvas class="chart chart-bar" height="250px" 
          chart-data="vm.data_gasto" 
          chart-colors="vm.data_colors" 
          chart-labels="vm.data_labels" 
          chart-options="vm.data_options" 
          ng-init="vm.chart_gasto()">
  </canvas>
  vm.options = {
    tooltips: {
      callbacks: {
        label: (tooltipItem, chart) => {
          const realValue = chart.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]
          const customValue = realValue.toFixed(2).replace(".", ",") + '%';
          const label = chart.labels[tooltipItem.index] + ':';
          return label + customValue;
        }
      }
    }
  }