1

I'm trying create a gantt chart with highcharts and I need to put the data in the JSON format. I'm getting real close, but the problem i'm having is that the data I am pushing is being surrounded by quotes. I'm guessing there is just something that I am doing wrong, but I can't figure it out.

I can tell that the issue is with quotes being added because i have some static data that works just fine and I printed the object in the firebug console for the static data and my dynamic data.

So here is the very basic of my options var:

var options = {
    series : [],
    test : [ {
        data : [ {
        low : Date.UTC(2012, 0, 1),
        y : Date.UTC(2012, 0, 15)
        }, {
        low : Date.UTC(2012, 0, 10),
        y : Date.UTC(2012, 4, 28)
        } ]
    }
}

Then I have this function which gets called at load time:

function loadData() {
    var chartData = $('#hiddenDate').val();
    console.log('hiddenDate = '+chartData);
    var goodData = chartData.split('|');
    console.log('goodData = '+goodData);

    var series = {
        data : []
    };

    try {
        $.each(goodData, function(index, value) {
            var goodData2 = value.split(",");
            var startYear = goodData2[0].substr(0, 4);
            var endYear = goodData2[1].substr(0, 4);
            var startMonth = goodData2[0].substr(5, 2);
            var endMonth = goodData2[1].substr(5, 2);
            var startDay = goodData2[0].substr(8, 2);
            var endDay = goodData2[1].substr(8, 2);
            /*series.data.push({
                low : 'Date.UTC('+startYear+','+startMonth+','+startDay+')',
                y : 'Date.UTC('+endYear+','+endMonth+','+endDay+')'
            });*/
            var start = "{low :  Date.UTC("+startYear+","+startMonth+","+startDay+")";
            var end = "y : Date.UTC("+endYear+","+endMonth+","+endDay+")}";
            series.data.push(start);
            series.data.push(end);
            //series.data.y.push('Date.UTC('+endYear+','+endMonth+','+endDay+')');
            console.log('series.data = '+series.data.toSource());
            console.log('options.test = '+options.test.toSource());
        });

        options.series.push(series);
        console.log('options.series = '+options.series.toSource());
    } catch (err) {
        console.log("ERROR ..." + err.description + '  message:'+ err.message);
    }
}

And here is the firebug output where I can see that the quotes are causing an issue for options.series:

series.data = ["{low : Date.UTC(2011,05,27)", "y : Date.UTC(2011,02,17)}", "{low : Date.UTC(2011,07,05)", "y : Date.UTC(2010,12,23)}"]
options.test = [{data:[{low:1325376000000, y:1326585600000}, {low:1326153600000, y:1338163200000}]}]
options.series = [{data:["{low : Date.UTC(2011,05,27)", "y : Date.UTC(2011,02,17)}", "{low : Date.UTC(2011,07,05)", "y : Date.UTC(2010,12,23)}"]}]

1 Answer 1

2

shouldn't your start and end variables be object literals instead of strings?

Sign up to request clarification or add additional context in comments.

1 Comment

Ahh yes that was it. As you can see from my commented piece I had tried that once, but I was getting comments around it and wasn't sure why so I tried a different approach - which obviously didn't work either. Thanks for pointing out the obvious for me. Cheers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.