It is currently Wed Aug 23, 2017 2:35 am Advanced search

Help needed to start Maps from Mysql

Technical support, bug reports and more.

Help needed to start Maps from Mysql

Postby cedric.reymond » Thu Jun 08, 2017 10:51 am

Hello,
I need some help to start creating a Map from MySQL table.
The table contains a ligne for each country in Europe with 5 column.
I would like to have a maps showing the different values like in this demo:
https://www.highcharts.com/maps/demo/tooltip
or
https://www.highcharts.com/maps/demo/rich-info

I have look at the code, and tried to adapt it, but I don't understand how to construct the data series with from my tables.
I have already used some highcharts graph fine, but here i am stucked.
Could someone drive me a little bit?

I have tried to remove this line and build an array instead, but it does not work...
$.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=world-population-density.json&callback=?', function (data) {

Thanks for your lights,
Cedric
cedric.reymond
 
Posts: 20
Joined: Tue Nov 29, 2016 7:17 pm

Re: Help needed to start Maps from Mysql

Postby d_paul » Thu Jun 08, 2017 1:43 pm

Hi Cedric,

Could you provide me with data which you want to use?

Regards.
Paweł Dalek
Highcharts Developer
d_paul
 
Posts: 1862
Joined: Thu Jun 02, 2016 12:28 pm

Re: Help needed to start Maps from Mysql

Postby cedric.reymond » Fri Jun 09, 2017 10:04 am

Hi Paul,
This is a sample of what I have in my table.
On mouse over of the country, it should display the values of the columns.

"ep_id";"ep_country";"ep_type";"ep_vol";"ep_app";"ep_pol";"ep_mdi";"ep_system";"ep_m2";"ep_pir"
"1";"FR";"flex";"11021";"17900";"25700";"747600";"74600";"23002000";"70"
"2";"FR";"rigid";"3100";"48060";"12564";"22312";"32012";"8456123";"40"
"3";"UK";"flex";"21200";"38400";"38500";"77800";"147650";"33500000";"0"
"4";"UK";"rigid";"3200";"18700";"18400";"35400";"50640";"13455645";"0"

Thanks for your help,
Cedric
cedric.reymond
 
Posts: 20
Joined: Tue Nov 29, 2016 7:17 pm

Re: Help needed to start Maps from Mysql

Postby d_paul » Fri Jun 09, 2017 4:13 pm

Hi Cedric,

It depends in what form you want to save/present provided data. I prepared a simple demo below.

API Reference:
http://api.highcharts.com/highmaps/tool ... tFormatter

Example:
http://jsfiddle.net/vzd7ec6v/

Regards.
Paweł Dalek
Highcharts Developer
d_paul
 
Posts: 1862
Joined: Thu Jun 02, 2016 12:28 pm

Re: Help needed to start Maps from Mysql

Postby cedric.reymond » Mon Jun 12, 2017 3:41 pm

Hi Paul,
Thanks for your help, I understand more now how it works.
Could you tell me how to get rid of the
$.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=world-population-density.json&callback=?',

part?
If I remove it the getjson call, it does not work..
I would like just to populate what is in the var dataBaseData from the mysql table.
cedric.reymond
 
Posts: 20
Joined: Tue Nov 29, 2016 7:17 pm

Re: Help needed to start Maps from Mysql

Postby d_paul » Mon Jun 12, 2017 6:01 pm

Hi Cedric,

The getJSON() function loads data from the server using a GET HTTP request, so if you remove it, there will not be any data to display on a chart. You need create a way to connect with your database, get the data, parse it and display it. Here you can find an example how to do it: https://www.highcharts.com/docs/working ... a-database. In case you have any further questions, do not hesitate to ask them.

API Reference:
http://api.jquery.com/jquery.getjson/

Regards.
Paweł Dalek
Highcharts Developer
d_paul
 
Posts: 1862
Joined: Thu Jun 02, 2016 12:28 pm

Re: Help needed to start Maps from Mysql

Postby cedric.reymond » Tue Jun 13, 2017 10:55 pm

Hi Paul,
I am really confused about what the json file contains.
Can't the map loads without any data?
On the demo you prepared me:
http://jsfiddle.net/vzd7ec6v/
my data is mixed with the demo data (population density).
So I was thinking that removing the json call will display the maps with my data only...
I would imagine Something like this with my data:
http://jsfiddle.net/5gn8dyag/2/

but this does not work:
http://jsfiddle.net/5gn8dyag/3/

I am sorry I am a bit lost with the dataBaseData usage
cedric.reymond
 
Posts: 20
Joined: Tue Nov 29, 2016 7:17 pm

Re: Help needed to start Maps from Mysql

Postby d_paul » Fri Jun 16, 2017 4:57 pm

Hi Cedric,

Sure, map can be loaded without any data (the first example). Your demo does not work because integration of default data and your data is incorrect. First of all, every point you want to display on a map has to have value and one id property used in linking with loaded map. As you can see, your data array contains points in a form of two elements array. The first one is mentioned above id property and the second is value. If you want to add your data from dataBaseData array, you need to cycle through all points of data array and add additional properties to appropriate point. Also, it will be easier to read if you change form of a point from an array to an object and use joinBy property, e.g.:

Code: Select all
['dk', 0]

to

Code: Select all
{
  code: 'dk',
  value: 0
}

Take a look at the updated example below.

API Reference:
http://api.highcharts.com/highmaps/plot ... map.joinBy

Examples:
http://jsfiddle.net/4yp9hwk5/
http://jsfiddle.net/mb4oh8ja/

Regards.
Paweł Dalek
Highcharts Developer
d_paul
 
Posts: 1862
Joined: Thu Jun 02, 2016 12:28 pm

Re: Help needed to start Maps from Mysql

Postby cedric.reymond » Mon Jun 19, 2017 9:35 am

Hi Paul,
Thanks for the explanation.
But your second link does not show any data from the dataBaseData array right?
cedric.reymond
 
Posts: 20
Joined: Tue Nov 29, 2016 7:17 pm

Re: Help needed to start Maps from Mysql

Postby d_paul » Mon Jun 19, 2017 4:24 pm

Hi Cedric,

Sorry, my bad. I forgot to convert code string to uppercase characters. Now, everything should work as expected.

API Reference:
https://developer.mozilla.org/en-US/doc ... oUpperCase

Example:
http://jsfiddle.net/5p1cgo40/

Regards.
Paweł Dalek
Highcharts Developer
d_paul
 
Posts: 1862
Joined: Thu Jun 02, 2016 12:28 pm

Re: Help needed to start Maps from Mysql

Postby cedric.reymond » Tue Jun 20, 2017 6:01 pm

Great I finally got it working.
Thanks a lot for your help on this, much appreciated!
cedric.reymond
 
Posts: 20
Joined: Tue Nov 29, 2016 7:17 pm

Re: Help needed to start Maps from Mysql

Postby cedric.reymond » Wed Jun 21, 2017 9:52 am

Hi Paul,
I replied too fast.
It works, but the data is not associated it is always showing the same values for all countries:
http://jsfiddle.net/5p1cgo40/1/

country codes are fine but the join is not done ...
I need your help again!
cedric.reymond
 
Posts: 20
Joined: Tue Nov 29, 2016 7:17 pm

Re: Help needed to start Maps from Mysql

Postby d_paul » Fri Jun 23, 2017 11:07 am

Hi Cedric,

You got rid of 'if', inside 'each' function. It is crucial, as it checks if point has the same id as country property from the data you want to add. Without it, each point get values destined for United Kingdom. Also, the id property (code property in this case) should be unique. Look at the updated code below.

Example:
http://jsfiddle.net/z0uu6mu2/

Regards.
Paweł Dalek
Highcharts Developer
d_paul
 
Posts: 1862
Joined: Thu Jun 02, 2016 12:28 pm

Re: Help needed to start Maps from Mysql

Postby cedric.reymond » Fri Jun 23, 2017 3:29 pm

ok got it.
Thanks a lot for your great help!
cedric.reymond
 
Posts: 20
Joined: Tue Nov 29, 2016 7:17 pm


Return to Highmaps Usage

Who is online

Users browsing this forum: No registered users and 0 guests