Php 如何将jqplot添加到定制Joomla(3.3)组件?

Php 如何将jqplot添加到定制Joomla(3.3)组件?,php,jquery,joomla,jqplot,Php,Jquery,Joomla,Jqplot,在开始使用Joomla之前,我开发了一个使用jqplot的html页面,该页面运行良好 现在我想在我正在开发的定制joomla(3.3)组件中包含jqplot,但是在调用该组件时(通过主菜单项),没有显示任何图表 进一步更新DEFAULT.PHP(JOOMLA)代码以注释: <?php // No direct access to this file defined('_JEXEC') or die('Restricted access'); $document = JFactory::g

在开始使用Joomla之前,我开发了一个使用jqplot的html页面,该页面运行良好

现在我想在我正在开发的定制joomla(3.3)组件中包含jqplot,但是在调用该组件时(通过主菜单项),没有显示任何图表

进一步更新DEFAULT.PHP(JOOMLA)代码以注释:

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
$document = JFactory::getDocument();

//add jqplot libraries
JHtml::_('jquery.framework');
$document->addScript(JPATH_ROOT.'/media/system/js/jquery.jqplot.min.js');
$document->addStyleSheet(JPATH_ROOT.'/media/system/js/jquery.jqplot.min.css');
$document->addScript(JPATH_ROOT.'/media/system/js/jqplot.barRenderer.min.js');
$document->addScript(JPATH_ROOT.'/media/system/js/jqplot.categoryAxisRenderer.min.js');
$document->addScript(JPATH_ROOT.'/media/system/js/jqplot.pointLabels.min.js');
$document->addScript(JPATH_ROOT.'/media/system/js/jqplot.enhancedLegendRenderer.js');
$document->addScript(JPATH_ROOT.'/media/system/js/weqlib.js');

?>

<head>
<script type="text/javascript">

    jQuery(document).ready(function(){
        var plot1 = jQuery.jqplot ('chart1', [[3,7,9,1,4,6,8,2,5]]); //copied from example at http://www.jqplot.com/tests/line-charts.php

    }); //$(document).ready
</script>
</head>

<!--<h1><?php echo $this->msg; ?></h1>-->
<h1>Prosumer Dashboard </h1>

<div id="chart1" style="width:600px; height:250px;"> </div>

jQuery(文档).ready(函数(){
var plot1=jQuery.jqplot('chart1',[[3,7,9,1,4,6,8,2,5]]);//复制自http://www.jqplot.com/tests/line-charts.php
}); //$(文件)。准备好了吗
Prosumer仪表板
我认为我调用libabries的方式是错误的(我确信jqplot函数调用是正确的,因为我也从我的旧html文件中复制了它)


你知道我做错了什么以及如何修复吗?

你应该用下面的方法将javascript添加到页面的头部

<?php
$document = JFactory::getDocument();
$document->addScript('/media/system/js/sample.js');
?>
请注意,这是在无冲突模式下运行的,因此您必须将jquery脚本中的任何“$”替换为“jquery”。您还可以使其在冲突模式下运行

JHtml::_('jquery.framework', false);

但是,如果您的站点正在运行任何其他库,这可能会导致问题。

您好,感谢您的评论,Richard。根据您的建议,我更改了default.php文件的代码,但是首页没有显示任何图形。另外,控制台显示了大量404错误,告诉它找不到jqplot js文件,我完全不理解,因为控制台中的路径与文件的路径匹配???注意,我包括了JPATH_根;如果没有这个常数,控制台也会显示404个错误加上错误的路径。我在笔记本电脑上运行Joomla(本地主机)
JHtml::_('jquery.framework', false);