我需要在一段时间内在prestashop页面上绘制一系列产品的销售价格图表,我只能静态地插入图表,在product.tpl的数组中手动输入数据:
{文字}
<script type = "text / javascript">
google.charts.load ('current', {packages: ['corechart', 'line']});
google.charts.setOnLoadCallback (drawChart);
function drawChart () {
var data = new google.visualization.DataTable ();
data.addColumn ('date', 'Date');
data.addColumn ('number', 'Price');
data.addRows ([
[new Date (5,15,2020), 10], [new Date (7,15,2020), 20],
[new Date (9,25,2020), 30]
]);
var options = {
hAxis: {
title: 'Date'
},
vAxis: {
title: 'Price'
},
lineWidth: 2,
pointSize: 8,
};
var chart = new google.visualization.LineChart (document.getElementById ('chart_div'));
chart.draw (data, options);
}
</script>
{/literal}
我想要得到任何产品的动态图表,这些产品从sql获取product_id并返回数据。
感谢您的帮助:)
发布于 2020-12-31 01:28:02
考虑创建一个模块来实现“Prestashop的方式”。
参见getting started,实现目标的最快方法是从可以使用Prestashop模块生成器构建的基本模块开始。
您可以使用您可以在产品页面中找到的hooks之一来显示图表内容,这样您就可以轻松地在module PHP类中获取产品数据,并将它们赋给图表的JS变量。
https://stackoverflow.com/questions/65508251
复制相似问题