Piter
Posts: 4
Joined: Sun Jul 31, 2016 10:13 am

name per point in scatter plot with highchart cloud

Hello,
I would like to have a name per point in a scatter plot chart. How can it be done? and is it possible with simple tools?
Thank you so much!
User avatar
KacperMadej
Posts: 4632
Joined: Mon Sep 15, 2014 12:43 pm

Re: name per point in scatter plot with highchart cloud

Hi Piter,

Yes, you could enable labels for points or to have different categories than point names you could set "explicit label column" in "custommize" > "simple" > "data series".
Demo: http://cloud.highcharts.com/show/inyjep

Kind Regards,
Kacper Madej
Highcharts Developer
Piter
Posts: 4
Joined: Sun Jul 31, 2016 10:13 am

Re: name per point in scatter plot with highchart cloud

Thank you so much!

I think that my problem was not clear, I'm sorry for this. What I want is to see the name of the points in the tooltip. I have a scatter plot with numeric values in both axes. http://cloud.highcharts.com/show/ykehad

I would like to show the name of the different points in the tooltip when you select one.

As you can see, I have designed a line as a regression line. It would be possible to show in the same tooltip the values/names for the points and the values of the regression line for each point? or maybe add a croshair line? All with Highcharts Cloud.

Thank you again!
User avatar
KacperMadej
Posts: 4632
Joined: Mon Sep 15, 2014 12:43 pm

Re: name per point in scatter plot with highchart cloud

Hi,

1. Yes, you could use mentioned 'custom code' input and loop over all series to find matching points like in this code:

Code: Select all

// Sample of extending options:
Highcharts.extend(options, Highcharts.merge(options, {
    plotOptions: {
        scatter: {
            tooltip: {
              pointFormatter: function(){
                var x = this.x,
                    ret = '';
                Highcharts.each(this.series.chart.series, function(s, i){
                  Highcharts.each(s.points, function(p, j){
                    if(p.x === x) ret += s.name + ': ' + p.x + ' / ' + p.y + '<br/>';
                  });
                });
                return ret;
              }
            }
        }
    }
}));
2. There is an error #15 in your chart - data for line plot is not sorted. It is not easy to notice but line between your points is not a simple line from the left-most to the right-most point, but between each point that are not sorted in asscending order by x - this is the source of the error. You could sort your data by x in ascending order to avoid duplicated line and the error visible in browser console.

Kind Regards.
Kacper Madej
Highcharts Developer
Piter
Posts: 4
Joined: Sun Jul 31, 2016 10:13 am

Re: name per point in scatter plot with highchart cloud

Thank you so much! This is awesome. I've added the first code and I'm solving the second problem. It's been difficult for me to write code, so I'm pleasure for your help. I would like to have a crosshair line, maybe a vertical one. Is it possible to add one? I've tried but I get no thing. But don't worry if it isn't possible, because as it is, is a great chart!
Thank you again!
Piter
Posts: 4
Joined: Sun Jul 31, 2016 10:13 am

Re: name per point in scatter plot with highchart cloud

Ouh! yes!

I've added:

tooltip: {
crosshairs: [true, true]
},

in the code.

Thank you so much!
Solved.

I would study the option of the license.
User avatar
KacperMadej
Posts: 4632
Joined: Mon Sep 15, 2014 12:43 pm

Re: name per point in scatter plot with highchart cloud

Hi,

I am glad to hear that your problems are solved. Feel free to ask if you have any more questions.

If you are interested in more advanced options you could take a look at the API reference - http://api.highcharts.com/highcharts

Kind Regards.
Kacper Madej
Highcharts Developer
PiterJones
Posts: 2
Joined: Wed Jun 20, 2018 5:42 am

Re: name per point in scatter plot with highchart cloud

Hi KacperMadej:

I'm Piter. I would like to know if since the last update of Highchart it is still possible to add name for points in a scatter chart. I have a chart like that in this page: http://secaba.ugr.es/rank/universitaria ... rsitarias/, but now I only achieve a chart like this one: https://cloud.highcharts.com/show/Bkkn0dLZm

Thank you so much!
daniel_s
Posts: 753
Joined: Fri Sep 01, 2017 11:01 am

Re: name per point in scatter plot with highchart cloud

Hi Piter,

The case is not as simple as using standard Highcharts, because there is no possibility to use String type values as a data field.
However, you can add another column in the data for labels, and then process existing data building your own parser for CSV. I prepared an example of how to achieve it using Highcharts Cloud. Please take a look on example below. The parser is implemented in "Custom code" tab.

Parser code:

Code: Select all

var data = options.data.csv;
var newSeries;
var oldSeriesOptions = options.series
console.log(options)

// Split the lines
var lines = data.split('\n');
lines.forEach(function(line, lineNo) {
  var items = line.split(';');
  
  // For first line create appropriate series
  if (lineNo === 0) {
  	newSeries = [{
      name: items[1],
      data: [],
      dataLabels: {
        format: "{point.label}",
      	enabled: true
      }
    }, {
      name: items[2],
      data: [],
      type: 'line',
      color: 'red',
      marker: {
      	enabled: true,
      }
    }]
  // Prepare data
  } else {
  	
    newSeries[0].data.push({
      x: parseInt(items[0]),
      y: parseInt(items[1]),
      label: items[3].slice(1, items[3].length -1)
    })
    
    newSeries[1].data.push({
      x: parseFloat(items[0]),
      y: parseFloat(items[2])
    })
    
  }

});
options.data.csv = null
options.series = newSeries
Live example : https://cloud.highcharts.com/show/SJYe2nwZ7

Best regards!
Daniel Studencki,
Highcharts Developer
PiterJones
Posts: 2
Joined: Wed Jun 20, 2018 5:42 am

Re: name per point in scatter plot with highchart cloud

Hi daniel_s:

It works! thank you so much for your work. I have a question: Do I need a license for the use of the option "custom code"?

Thank you so much.
daniel_s
Posts: 753
Joined: Fri Sep 01, 2017 11:01 am

Re: name per point in scatter plot with highchart cloud

hi Piter,

I think yes, but please contact our sales team and ask the question. Here is the email adress:
[email protected]

Best regards!
Daniel Studencki,
Highcharts Developer
Jeffrey Phillips
Posts: 56
Joined: Tue Aug 30, 2016 9:32 pm

Re: name per point in scatter plot with highchart cloud

daniel_s wrote:Hi Piter,

The case is not as simple as using standard Highcharts, because there is no possibility to use String type values as a data field.
However, you can add another column in the data for labels, and then process existing data building your own parser for CSV. I prepared an example of how to achieve it using Highcharts Cloud. Please take a look on example below. The parser is implemented in "Custom code" tab.

Parser code:

Code: Select all

var data = options.data.csv;
var newSeries;
var oldSeriesOptions = options.series
console.log(options)

// Split the lines
var lines = data.split('\n');
lines.forEach(function(line, lineNo) {
  var items = line.split(';');
  
  // For first line create appropriate series
  if (lineNo === 0) {
  	newSeries = [{
      name: items[1],
      data: [],
      dataLabels: {
        format: "{point.label}",
      	enabled: true
      }
    }, {
      name: items[2],
      data: [],
      type: 'line',
      color: 'red',
      marker: {
      	enabled: true,
      }
    }]
  // Prepare data
  } else {
  	
    newSeries[0].data.push({
      x: parseInt(items[0]),
      y: parseInt(items[1]),
      label: items[3].slice(1, items[3].length -1)
    })
    
    newSeries[1].data.push({
      x: parseFloat(items[0]),
      y: parseFloat(items[2])
    })
    
  }

});
options.data.csv = null
options.series = newSeries
Live example : https://cloud.highcharts.com/show/SJYe2nwZ7

Best regards!
Great. Now open that chart in HC Cloud and (try to) edit it …

Return to “Highcharts Cloud”