用chartjs定义级别

时间:2018-11-09 14:40:00

标签: php jquery chart.js prestashop

您好,我使用Chartsjs创建动态图形,并尝试在图表中添加一些内容。我想显示4个方位并根据结果显示最接近的水平,例如:

我有4个等级: 1-700.000 2-1.500.000 3-5.500.000 4-12.000.000

我的最高数字是500.000,我必须在第一级显示一个红色的条带是700.000,当我过去时,我将显示1.500.000,等等...

这是我当前的图表: graph

var ctx = document.getElementById("chiffreAffaire");
var stackedBar = new Chart(ctx, {
  type: 'bar',
  data: {
    labels: ["01/18", "02/18", "03/18", "04/18", "05/18", "06/18", "07/18", "08/18", "09/18", "10/18", "11/18", "12/18"],
    datasets: [{
      data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 6555, 6332, 0],
      backgroundColor: [
        'rgba(255, 99, 132, 0.6)',
        'rgba(54, 162, 235, 0.6)',
        'rgba(255, 206, 86, 0.6)',
        'rgba(75, 192, 192, 0.6)',
        'rgba(153, 102, 255, 0.6)',
        'rgba(255, 159, 64, 0.6)',
        'rgba(255, 99, 132, 0.6)',
        'rgba(54, 162, 235, 0.6)',
        'rgba(255, 206, 86, 0.6)',
        'rgba(75, 192, 192, 0.6)',
        'rgba(153, 102, 255, 0.6)',
        'rgba(255, 159, 64, 0.6)'
      ]
    }]
  },
  options: {
    legend: false,
    responsive: true,
    title: {
      display: true,
      text: 'Chiffre d\'affaire - année ' + new Date().getFullYear()
    },
    scales: {
      yAxes: [{
        scaleLabel: {
          display: true,
          labelString: 'Chiffre d\'affaire (DA)'
        },
        ticks: {
          beginAtZero: true
        }
      }]
    }
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
<canvas id="chiffreAffaire" width="400" height="150"></canvas>

我必须在X中显示700.000

感谢帮助。

0 个答案:

没有答案
相关问题