1

我正在尝试使用经典 ASP 中 SQL Server 的结果填充 HighCharts 数据集,但似乎无法正确获取语法。这是我自定义的一个非常基本的开始,我想得到数据集渲染,从那里一切都很容易。

下面的循环工作正常,并且正在从我的存储过程中正确获取数据。我相信我的问题data[]在实际部分的var options =部分

dim xAxisData()
dim yAxisData()
j = 0               
    adoRsGraph.MoveFirst

if adoRsGraph.EOF = false then

    Do Until adoRsGraph.EOF
        reDim xAxisData(j)
        reDim yAxisData(j)
            xAxisData(j) = adoRsGraph("Value")
            yAxisData(j) = adoRsGraph("Date")

        j = j + 1
        adoRsGraph.MoveNext
    Loop

end if



$(function () { 
        var options = {
        chart:{
            type:'line',
            renderTo: 'chartContainer'               
            },
        xAxis: {
            categories: ['Apples','Bananas','Oranges']
        },
        yAxis: {
            title:{
                text: 'Assets'          
            }
        },
        series: [{
            name: 'Dates',
            data: [<% For Each item In yAxisData    Response.Write(item & ",") Next %>],
            color: '#006600'
        }]
    }
var chart3 = new Highcharts.Chart(options); 
});

接收错误;

Microsoft VBScript compilation 
Description:Expected end of statement
Line:90

第 90 行是;

data: [<% For Each item In yAxisData    Response.Write(item & ",") Next %>],
4

1 回答 1

4

恕我直言,我认为最好将将数据转换为逗号分隔列表的逻辑分解为函数。preserve当您重新调整数组时,我还添加了。否则您将丢失数据。

dim xAxisData()
dim yAxisData()
j = 0               
    adoRsGraph.MoveFirst

if adoRsGraph.EOF = false then
    Do Until adoRsGraph.EOF
        reDim preserve xAxisData(j)
        reDim preserve yAxisData(j)
        xAxisData(j) = adoRsGraph("Value")
        yAxisData(j) = adoRsGraph("Date")

        j = j + 1
        adoRsGraph.MoveNext
    Loop
end if

$(function () { 
    var options = {
    chart:{
        type:'line',
        renderTo: 'chartContainer'               
        },
    xAxis: {
        categories: ['Apples','Bananas','Oranges']
    },
    yAxis: {
        title:{
            text: 'Assets'          
        }
    },
    series: [{
        name: 'Dates',
        data: [<%= GetYAxisData() %>],
        color: '#006600'
    }]
}
var chart3 = new Highcharts.Chart(options); 
});

您发布的原始代码For Each item In yAxisData Response.Write(item & ",")会在末尾创建一个额外的逗号 (,),从而导致意外行为。我认为使用 Join() 函数是一个更好的选择。

function GetYAxisData()
    GetYAxisData = Join(yAxisData, ",")
end function
于 2013-10-29T14:08:09.277 回答