jsReport 没有通过 javascript 读取数据
jsReport not reading data through javascript
我正在使用 jsreport.net 创建报告。我正在尝试使用一组数据将其放入使用 JavaScript 运行的图表中,但我无法将数据调用到 JavaScript。我之前发疯的一个table作品如下:
<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}}"
利润需要是整数而不是字符串
使用资产全局函数将数据转换为 js 字符串 helpers.js
这导致类似 var data = { "a": "foo" }
之后在 chrome 中被解释为对象
var obj = {{{toJS 日期}}};
我正在使用 jsreport.net 创建报告。我正在尝试使用一组数据将其放入使用 JavaScript 运行的图表中,但我无法将数据调用到 JavaScript。我之前发疯的一个table作品如下:
<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}}"
利润需要是整数而不是字符串
使用资产全局函数将数据转换为 js 字符串 helpers.js
这导致类似 var data = { "a": "foo" }
之后在 chrome 中被解释为对象
var obj = {{{toJS 日期}}};