javascript - jsReport不通过javascript读取数据
问题描述
我正在使用 jsreport.net 创建报告。我正在尝试使用一组数据将其放入使用 JavaScript 运行的图表中,但我无法将数据调用到 JavaScript。我之前疯狂的一张桌子,它如下:
<div id="table" style="height: 300px; width: 50%;">
<table>
<thead>
<tr>
<th style="border: 1px solid">Date of restock</th>
<th style="border: 1px solid">Units sold</th>
<th style="border: 1px solid">Total profit</th>
</tr>
</thead>
<tbody>
{{#each sale}}
<tr>
<td style="border: 1px solid">{{date}}</td>
<td style="border: 1px solid">{{units}}</td>
<td style="border: 1px solid">R {{profit}}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
我的数据如下所示:
{
"sale":[{
"date":"20 January 2018",
"units":"549",
"profit":"1514"
},{
"date":"16 February 2018",
"units":"483",
"profit":"1332"
},{
"date":"23 March 2018",
"units":"678",
"profit":"2596"
}]
}
图表如下所示:
<script>
window.onload = function () {
var chart= new CanvasJS.Chart("chartContainer2", {
animationEnabled: true,
theme: "light2",
title:{
text: "Progress of the number of units sold per restock"
},
axisY:{
includeZero: false
},
data: [{
type: "line",
dataPoints: [
{{#each sale}}
{ y: {{profit}}, label: {{date}} }
{{/each}}
]
}]
});
chart.render();
}
</script>
<div id="chartContainer2" style="height: 300px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
我是这个 jsreport 的新手,所以如果我遗漏了什么,请不要责骂我。请帮我解决这个问题。
解决方案
我想到了。它所需要的只是日期周围的引号。
"{{date}}"
并且利润需要一个整数而不是一个字符串
推荐阅读
- python - 我在烧瓶中遇到端口问题,如何更改端口?
- r - 将格式应用于 R 中的多个数组
- python-3.x - ArgumentError: hasproperty of NULL PyObject using PyPlot in julia 1.5.3 in JupyterNotebook
- r - 模型适合 Lavaan CFA。这段代码有什么问题?
- shell - 从最后一个字符开始的字符串 shell 脚本中的子字符串
- web - 网站未从 www 重定向到 https
- spring-security - 永远不会调用 Spring 安全过滤器
- opencv - OpenCV 文本检测
- django - Django url前缀关联
- android - 未解决的参考:requireLensFacing | 安卓工作室