我希望在我的Joomla组件“bestia”中使用chart.js。为此,我在manifest.xml中将chart.js作为媒体元素导入。
我的调用方式如下:
我该怎么办?
我的调用方式如下:
JHtml::script(Juri::root() . 'media/com_hostinghelden/chartjs/Chart.js');
现在我想使用helper来简化一些操作。我的helper应该绘制一个图形...abstract class JHtmlGraphs
{
public function draw($title = NULL, $labelset = NULL, $data = NULL, $data2 = NULL)
{
$script = "<script> var barChartData_$title = { labels : [ {$labelset} ], datasets : [ { fillColor : 'rgba(220,220,220,0.5)', strokeColor : 'rgba(220,220,220,0.8)', highlightFill: 'rgba(220,220,220,0.75)', highlightStroke: 'rgba(220,220,220,1)', data : [ $data ] }, { fillColor : 'rgba(151,187,205,0.5)', strokeColor : 'rgba(151,187,205,0.8)', highlightFill : 'rgba(151,187,205,0.75)', highlightStroke : 'rgba(151,187,205,1)', data : [ $data2 ] } ] }; window.onload = function(){ var ctx_$title = document.getElementById('canvas_$title').getContext('2d'); window.myBar = new Chart(ctx_$title).Bar(barChartData_$title, { responsive : true }); } </script>";
$canvas = "<div style='width: 100%'><canvas id='canvas_$title' height='20' width='20'></canvas></div>";
return $script . $canvas;
}
}
如果我将它命名为Jhtml-Graphs,则图形将被正确地呈现:
<?php echo JHtml::_('graphs.draw', "Titel", $labelset, $data, $data2); ?>
但是,如果我想在页面上添加第二个图表,则第一个图表将不再显示:
<?php echo JHtml::_('graphs.draw', "Titel2", $labelset, $data, $data2); ?>
我该怎么办?