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'),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,0.8)",highlightFill: "rgba(100,149,237,0.75)",highlightStroke: "rgba(100,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,}]
},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>
这对我来说可能只是一个愚蠢的错误。预先感谢您的帮助!