首页 > 解决方案 > 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 的新手,所以如果我遗漏了什么,请不要责骂我。请帮我解决这个问题。

标签: javascripthtmljsonjsreport

解决方案


我想到了。它所需要的只是日期周围的引号。

"{{date}}"

并且利润需要一个整数而不是一个字符串


推荐阅读