1
votes

So i asked a couple of days ago Here as to which charts one can use for Stock based applications and i finally settled with HighCharts Simply because its so awesome.

Now my chart renders this way and it is as expected.

Candlestick chart

The next step for me is to place flags on them . Which i am able to do while creating the chart itself and it renders like this:

Candlestick with flag

// some code here
series: [{
                        id: "dataSeries",
                        name: "datadata",
                        type: "candlestick",
                        data: items
                    },{
                         id: "flagSeries",
                         name: "flagflag",
                         type: "flags",
                         data: [{
                             x: 1301651400000,
                             title: 'B',
                             text: 'Shape: "circlepin"'
                         }]
                    }]
// some code here

But when i try to do the same dynamically as directed here , i get an error that says Uncaught TypeError: Cannot read property 'shift' of undefined

//some code here
series: [{
                        id: "dataSeries",
                        name: "datadata",
                        type: "candlestick",
                        data: items
                    },{
                         id: "flagSeries",
                         name: "flagflag",
                         type: "flags",
                         data: []
                    }]
//some code here
$('button').click(function(){
var ser = chart.get("flagSeries");
                console.log(ser);
                ser.addPoint({
                    x: 1301672700000,
                    title: 'C',
                    text: 'Shape: "circlepin"'
                });
});
//some code here

How come it works there but not when i try it ? :(

1
when are you getting the error ? onClick or onLoad ? maybe you add point to wrong/non-exisiting series ? jsfiddle.net/CAKQH/5 - dynamic addPoint() works ...c69
i get the error when i click on the button . The thing is , the code that is found here when put on my local machine , gives that error also . i dont understand how it can work online but not on a local machine :(Shrayas
do you have same version of HighCharts as on site (ie: most fresh)?c69
your code from [here][jsfiddle.net/3ZdBd/] does not work in none of my browsers. FF / Chr / Op - just graph, and when you click, nothing chages. IE9 - weird button, which does nothing, and no graph.c69

1 Answers

1
votes

A great thanks owed to @c69 who helped me on this .

Apparantly the version they were giving out for download wasn't the one they were using on jsFiddle .

Also i was trying to use the getData function that gave me the problems (because of a bug in the highcharts.js) . But later we understood and we started using the addPoint method instead .

Now it works :D

var entry_servlet = 'SOMESERVLET'

    $.getJSON(entry_servlet, function(ret_data) {

        $.each(ret_data, function(key, val) {

            var dat = ret_data[key].date;
            var tim = ret_data[key].time;

            var o = ret_data[key].o;
            var h = ret_data[key].h;
            var l = ret_data[key].l;
            var c = ret_data[key].c;



            datArr = dat.split('/');
            timArr = tim.split(':');

            var UTCthing;


            UTCthing = Date.UTC(datArr[2],datArr[0]-1,datArr[1],timArr[0],timArr[1],timArr[2]);



            window.buck_chart.series[1].addPoint(
                    { 

                            name:'title',
                            title: "B", 
                            x: UTCthing,
                            color: '#009f3c',
                           text: "Price:  " + o + " time:  " + tim                                              
                    },true,false);  

    });

    });