Chartjs:如何在条形图上显示值?

时间:2019-12-12 02:05:22

标签: chart.js

这是我的带有ChartJS 2.3.0,PHP和Mysql的条形图。

          <script>
          new Chart(document.getElementById("chartjs-7"),{
            "type":"bar",
            "data":{
              "labels":["Jan","Feb","Mar","Apr","Mei","Jun","Jul","Ags","Sep","Okt","Nov","Des"],
              "datasets":[{
                "label":"T2019",
                "data":[118,97,130,178,142,154,176,182,178,187,200,290],
                "borderColor":"#093B6E",
                "backgroundColor":"#093B6E"
              },{
                "label":"R2019",
                "data":[<?php while ($data_rbar = mysqli_fetch_array($result_rbar)) {echo $data_rbar["Jan"].",".$data_rbar["Peb"].",".$data_rbar["Mar"].",".$data_rbar["Apr"].",".$data_rbar["Mei"].",".$data_rbar["Jun"].",".$data_rbar["Jul"].",".$data_rbar["Ags"].",".$data_rbar["Sep"].",".$data_rbar["Okt"].",".$data_rbar["Nov"].",".$data_rbar["Des"];} ?>],
                "type":"bar",
                "fill":false,
                "borderColor":"#F8C11D",
                "backgroundColor":"#F8C11D"
              },{
                "label":"R2018",
                "data":[<?php while ($data_rbar_prev = mysqli_fetch_array($result_rbar_prev)) {echo $data_rbar_prev["Jan"].",".$data_rbar_prev["Peb"].",".$data_rbar_prev["Mar"].",".$data_rbar_prev["Apr"].",".$data_rbar_prev["Mei"].",".$data_rbar_prev["Jun"].",".$data_rbar_prev["Jul"].",".$data_rbar_prev["Ags"].",".$data_rbar_prev["Sep"].",".$data_rbar_prev["Okt"].",".$data_rbar_prev["Nov"].",".$data_rbar_prev["Des"];} ?>],
                "type":"bar",
                "fill":false,
                "borderColor":"#A3ABB2",
                "backgroundColor":"#A3ABB2"
              }]
            },
            "options":{"scales":{"yAxes":[{"ticks":{"beginAtZero":true}}]}}
          }
          );
          </script>

结果: enter image description here

如何像这样在条形图的顶部显示值?

enter image description here

非常感谢您

0 个答案:

没有答案