bomortensen
Posts: 9
Joined: Thu Mar 15, 2012 12:56 am

Show tooltip for latest/last point on loaded

Hi all,

I'm a happy user of the highstock chart, but I'm running my head against the wall on this 'problem'. My client has asked me if it's possible to show the tooltip of the last point in the chart when it's loaded (I'm loading series with AJAX call from a webservice)

I've tinkered around with the .refresh() method, but without any luck so far :-/ I'm wondering if this is possible and if someone has got a sample of it somewhere to get me kicked in on it?

Thanks a lot in advance.

All the best,

Bo Mortensen
bomortensen
Posts: 9
Joined: Thu Mar 15, 2012 12:56 am

Re: Show tooltip for latest/last point on loaded

I guess no one have made this before. I'll post/mail it as a feedback topic then :-)
bomortensen
Posts: 9
Joined: Thu Mar 15, 2012 12:56 am

Re: Show tooltip for latest/last point on loaded

Got a bit further with this: got hold of the last point of the graph when it's loaded, now I *just* need to be able to actually show the tooltip of the point. Anyone's got an idea of how to do this? :-)

Fiddle for reference: http://jsfiddle.net/L2TFd/9/

Thanks in advance.

- Bo
bomortensen
Posts: 9
Joined: Thu Mar 15, 2012 12:56 am

Re: Show tooltip for latest/last point on loaded

And another update:

I actually managed to show the last points tooltip when the graph has been loaded, but it only shows the data for the first serie when there's more than one serie in my graph.

Fiddle: http://jsfiddle.net/L2TFd/26/

Is there any way to make it show the data from the other series in the tooltip? :-)
Fusher
Posts: 7912
Joined: Mon Jan 30, 2012 10:16 am

Re: Show tooltip for latest/last point on loaded

As I know it may be not possible without hacking sources.
Paweł Fus
Highcharts Developer
trinhthanhdung
Posts: 119
Joined: Fri Jul 15, 2011 7:59 am

Re: Show tooltip for latest/last point on loaded

Hi, please check my link
http://jsfiddle.net/L2TFd/28/
I've already shown last point on loaded for all series.
Fusher
Posts: 7912
Joined: Mon Jan 30, 2012 10:16 am

Re: Show tooltip for latest/last point on loaded

Nice!
Paweł Fus
Highcharts Developer
bomortensen
Posts: 9
Joined: Thu Mar 15, 2012 12:56 am

Re: Show tooltip for latest/last point on loaded

Thank you so much, trinhthanhdung! Greatly appreciated :-)

My final code looks like this:

Code: Select all

chart: {                        
                        height: 210,
                        renderTo: 'graph',
                        events: {
                          load: function(event) {
                            var chart = $(this);                            
                            var jsonArray = $.parseJSON(data);
                            var lastArray = $(jsonArray).last();
                            
                            // Zoom in on last data point
                            if($(lastArray).length > 0) {                            
                              var unixDate = lastArray[0][0];
                              var currentDate = new Date(unixDate);
                              chart[0].xAxis[0].setExtremes(Date.UTC(currentDate.getFullYear(), currentDate.getMonth() - 1, currentDate.getDate()), Date.UTC(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()));                              
                            }
                            
                            // Show tooltip for last point in all series
                            try {
                              var points=[];
                              if(chart)
                              {
                                var points = [];
                                for(var i = 0; i < chart[0].series.length; i++) {
                                  var point = chart[0].series[i].points[chart[0].series[i].points.length-1];
                                  if(point) {
                                    points.push(point);
                                  }
                                } 
                                chart[0].tooltip.refresh(points);        
                              } 
                            } catch(e) {}                           
                          }
                        }                       
                    }

Return to “Highcharts Stock”