无法将包含数字值的java变量解析为Highcharts series.data

时间:2017-02-23 23:38:43

标签: javascript java highcharts

我已经为使用Highcharts API创建的javascript函数附加了我的代码。我被困在series.data输入。每当我尝试在数据数组中的y值中传入变量staffSales时,我得到一个错误,指出"字符串值发送到series.data,期望Number"。我试图改变传递数据的方式,但无济于事。请有人帮我这个。

- 代码开始 -

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>


<script src="https://code.highcharts.com"></script>   
<script type="text/javascript">
$(function () {
    // Create the chart
    Highcharts.chart('container', {
        chart: {
            type: 'column'
        },
        title: {
            text: 'Hairstylists Sales Breakdown'
        },
        subtitle: {
            text: '<%= month %>'
        },
        xAxis: {
            type: 'category'
        },
        yAxis: {
            title: {
                text: 'Sales($)'
            }
        },
        legend: {
            enabled: false
        },
        plotOptions: {
            series: {
                borderWidth: 0,
                dataLabels: {
                    enabled: true,
                    format: '{point.y:.1f}%'
                }
            }
        },

        tooltip: {
            headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
            pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>'
        },

        series: [{
            name: 'Sales',
            colorByPoint: true,
            data: [
                <%
                    List<User> users = UserDAO.retrieveStaffList();
                    for(int i = 0; i < users.size(); i++){
                        User u = users.get(i);
                        String staffName = u.getName();
                        String staffUsername = u.getUsername();
                        double staffSales = PaymentDAO.monthlySalesbyUser(m, y, staffUsername);
String salesNo = staffSales + "";
                %>
            {
                name: '<%= staffName %>',
                y: parseFloat(<%= salesNo %>) 
            },
                <% } %>
            ]
        }]
    });
});

0 个答案:

没有答案