Chart.js注释插件-注释未出现在Wordpress模板中

问题描述 投票:0回答:1

chart.js 注释插件在我的wordpress模板中表现不正常。图表可以很好地显示,但注释不会出现。我试过将注释配置放在“插件”中,并且在选项下也无济于事。最后,我尝试将codepen示例复制粘贴到我自己的代码中,并得到相同的结果-没有注释。现在我很困惑:p

我确实(在我看来)在登台服务器上复制了this code pen example,但是尽管注释(一行)出现在代码笔中,但它并未出现在我的网站上。我认为(?)我安装了所有版本的相同版本,并且已将注释插件排队,以将chart.js列为依赖项。请让我知道我做错了!

从我的插件文件(fws_wpt_pdf.php):

        wp_enqueue_script( 'chart_js', "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.2.1/Chart.min.js", array('jquery'), false, true );
        wp_enqueue_script( 'chart_annotation_js', 'https://cdn.rawgit.com/chartjs/chartjs-plugin-annotation/master/chartjs-plugin-annotation.js', array('chart_js'), false, true );

从我的javascript文件(fws_pdf.js):

var canvas = $(selector)[0];
var ctx = canvas.getContext('2d');

var data = {
    labels: ["2010", "2011", "2012", "2013", "2014", "2015", "2016"],
    datasets: [
        {
            label: "My Second dataset",
            fillColor: "rgba(0,191,255,0.5)",
            strokeColor: "rgba(0,191,255,0.8)",
            highlightFill: "rgba(100,149,237,0.75)",
            highlightStroke: "rgba(100,149,237,1)",
            data: [60, 50, 40, 30, 20, 10, 20],
            borderColor: 'grey',
            borderWidth: 1,        
        }
    ]};

    var options = {
    legend: {
      display: true,
    },
    tooltips: {
      enabled: false,
    },
    scales: {
      xAxes: [{
        display: true,
          ticks: {
                    beginAtZero:true
                },        
      }],
      yAxes: [{
        display: true,
                  ticks: {
                    beginAtZero:true
                },        
      }]
    },      
      annotation: {
        annotations: [{
            type: 'line',
            mode: 'vertical',
            scaleID: 'y-axis-0',
            value: '26',
            borderColor: 'black',
            borderWidth: 3
        }],
        drawTime: "afterDraw" // (default)
    }
  };

// Chart declaration:
var multiLineChart = new Chart(ctx, {
  type: 'bar',
  data: data,
  options: options
});

从我的模板文件(entry-content-wpt-test-get-results.php):

    <div class="chart-wrapper">
        <canvas id="test_chart" data-label="<?php echo $result->getTitle() ?>" data-x_value="<?php echo $scales[1]->getValue(); ?>" data-y_value="<?php echo $scales[0]->getValue(); ?>" data-x_max_value="<?php echo $scales[1]->getMaximum(); ?>" data-y_max_value="<?php echo $scales[0]->getMaximum(); ?>"></canvas>
    </div>

这可能对我来说只是一个愚蠢的错误。预先感谢您的帮助!

wordpress chart.js2
1个回答
0
投票

我找到了答案!我正在为较旧的Wordpress主题开发模板,它强制使用jQuery 1.8(!)。当我停止这样做并加载最新的jQuery(3.4.1)时,注释再次开始起作用[[whew! )

© www.soinside.com 2019 - 2024. All rights reserved.