Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts naming of individual bubbles

Tags:

highcharts

The new Highcharts v3.0 bubble chart looks great. Is it possible to annotate and display each bubble with a name/some text? Thanks, Nigel.

like image 636
user2150801 Avatar asked Mar 09 '13 05:03

user2150801


People also ask

What is packed bubble?

Packed bubble charts are visualizations where the size and optionally the color of the bubbles are used to visualize the data. The positioning of the bubbles is not significant, but is optimized for compactness.

What language is used in Highcharts?

Highcharts is a software library for charting written in pure JavaScript, first released in 2009. The license is proprietary.


2 Answers

There are two things you need to do.

First, name each data point (bubble):

data: [
  { name: 'Alice', x: 3.5, y: 4, z: 5}, 
  { name: 'Eve', x: 7, y: 7, z: 3}, 
  { name: 'Carol', x: 4, y: 8, z: 6}
]

Second, create a data label formatter:

dataLabels: {
  enabled: true,
  formatter: function() {
    return this.point.name;
  }
}

You can see this in action here: http://jsfiddle.net/franzo/JuGDp/1/

Bob's your uncle.

like image 131
franzo Avatar answered Oct 01 '22 04:10

franzo


Depending on what you want to display, it should be possible. The bubble charts will allow the same options as any other highcharts. The easiest way is to use dataLabels http://api.highcharts.com/highcharts#plotOptions.scatter.dataLabels

       dataLabels:{
           enabled:true
       } 

e.g. http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/plotoptions/series-datalabels-box/

If that isn't flexible enough for you, it is possible to draw whatever you want on the chart using the underlying renderer http://api.highcharts.com/highcharts#Renderer. This is a bit harder, but. Fairly straight forward once you get the hang of it.

I've created a small example using datalabels here :http://jsfiddle.net/4nRk6/

Datalabels can be customised with a formatter function, for example:

 dataLabels: {
           enabled: true,
           formatter: function() {
                    return this.y +'mm';
           }
 }  

The full documentation is here: http://api.highcharts.com/highcharts#plotOptions.column.dataLabels

If you want extra information on the bubbles, you may need to format your data series as follows:

[
    {x:1, y:5, bubbleText:"Bubble 1"},
    {x:2, y:15, bubbleText:"Bubble 2"},
    {x:3, y:5, bubbleText:"Bubble 3"}
]

Inside your dataLabel, you can then reference this.point.bubbleText as well as this.x and this.y.

like image 34
SteveP Avatar answered Oct 01 '22 03:10

SteveP