Chart.js标签未显示

时间:2019-03-13 17:47:26

标签: codeigniter charts chart.js linechart

该图表可以正常工作,但是如果用户不知道线条的含义(因为它没有标签),就会有点错过。 我尝试了多种方法使标签显示在图表上,但仍然无法正常工作。控制台不告诉任何错误。也许有人会帮助我?我尝试不放置“'”字,但是图表变成空白。

<script src="<?=HTTP_PATH.'bower_components/chart.js/Chart.js'?>"></script>
<script>
    var areaChartData = {
      labels  : [<?php foreach ($year as $v) {echo "{$v->a},";}?>],
      datasets: [
      {
          label               : 'Minimal Keuntungan',
          fillColor           : 'rgba(140, 33, 33, 1)',
          strokeColor         : 'rgba(140, 33, 33, 1)',
          pointColor          : 'rgba(140, 33, 33, 1)',
          pointStrokeColor    : '#d24141',
          pointHighlightFill  : '#fff',
          pointHighlightStroke: 'rgba(140, 33, 33, 1)',
          data                : `[<?php foreach ($xmin as $v) {echo "{$v->min},";}?>],`
      },
      {
          label               : 'Maksimal Keuntungan',
          fillColor           : 'rgba(60,141,188,0.9)',
          strokeColor         : 'rgba(60,141,188,0.8)',
          pointColor          : '#3b8bba',
          pointStrokeColor    : 'rgba(60,141,188,1)',
          pointHighlightFill  : '#fff',
          pointHighlightStroke: 'rgba(60,141,188,1)',
          data                : [<?php foreach ($xmax as $v) {echo "{$v->max},";}?>],
      },
      {
          label               : 'Rata-rata Keuntungan',
          fillColor           : 'rgba(32, 95, 22, 1)',
          strokeColor         : 'rgba(32, 95, 22, 1)',
          pointColor          : '#205f16',
          pointStrokeColor    : 'rgba(32, 95, 22, 1)',
          pointHighlightFill  : '#fff',
          pointHighlightStroke: 'rgba(32, 95, 22, 1)',
          data                : [<?php foreach ($xavg as $v) {echo "{$v->avg},";}?>],
      }
      ]
  }
  var areaChartOptions = {
      //Boolean - If we should show the scale at all
      showScale               : true,
      //Boolean - Whether grid lines are shown across the chart
      scaleShowGridLines      : true,
      //String - Colour of the grid lines
      scaleGridLineColor      : 'rgba(0,0,0,.05)',
      //Number - Width of the grid lines
      scaleGridLineWidth      : 1,
      //Boolean - Whether to show horizontal lines (except X axis)
      scaleShowHorizontalLines: true,
      //Boolean - Whether to show vertical lines (except Y axis)
      scaleShowVerticalLines  : true,
      //Boolean - Whether the line is curved between points
      bezierCurve             : true,
      //Number - Tension of the bezier curve between points
      bezierCurveTension      : 0.3,
      //Boolean - Whether to show a dot for each point
      pointDot                : true,
      //Number - Radius of each point dot in pixels
      pointDotRadius          : 4,
      //Number - Pixel width of point dot stroke
      pointDotStrokeWidth     : 1,
      //Number - amount extra to add to the radius to cater for hit detection outside the drawn point
      pointHitDetectionRadius : 20,
      //Boolean - Whether to show a stroke for datasets
      datasetStroke           : true,
      //Number - Pixel width of dataset stroke
      datasetStrokeWidth      : 2,
      //Boolean - Whether to fill the dataset with a color
      datasetFill             : true,
      //String - A legend template
      legendTemplate          : '<ul class="<%=name.toLowerCase()%>-legend"><% for (var i=0; i<datasets.length; i++){%><li><span style="background-color:<%=datasets[i].lineColor%>"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>',
      //Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
      maintainAspectRatio     : true,
      //Boolean - whether to make the chart responsive to window resizing
      responsive              : true
  }
    //-------------
    //- LINE CHART -
    //--------------
    var lineChartCanvas          = $('#lineChart').get(0).getContext('2d')
    var lineChart                = new Chart(lineChartCanvas)
    var lineChartOptions         = areaChartOptions
    lineChartOptions.datasetFill = false
    lineChart.Line(areaChartData, lineChartOptions)
</script>

0 个答案:

没有答案