Nick G
Nick G

Reputation: 1229

HighCharts data from SQL Server, classic asp

I'm trying to populate a HighCharts dataset with results from SQL Server in Classic ASP, but can't seem to get the syntax down correctly. This is a very basic beginning to my customization, I figure get the datasets rendering and everything is easy from there.

The below loop is working correctly, and is grabbing the data correctly from my sproc. My issue I believe is in the data[] section of the actual var options = section

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); 
});

receiving error of;

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

with line 90 being;

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

Upvotes: 1

Views: 1359

Answers (1)

David
David

Reputation: 1613

IMHO I think it would be better to break out the logic that transforms the data into a comma separated list into a function. I also added preserve when you redim the arrays. Otherwise you will lose data.

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); 
});

The original code you posted For Each item In yAxisData Response.Write(item & ",") would create an extra comma (,) at the end leading to unexpected behaviour. Using Join() function is a better option I think.

function GetYAxisData()
    GetYAxisData = Join(yAxisData, ",")
end function

Upvotes: 4

Related Questions