radiance32
Posts: 18
Joined: Thu Apr 08, 2021 4:10 am

Re: multiple charts on one page with shared x-axis view/range selection/zoom

pawelys wrote: Mon Apr 26, 2021 9:02 am You're welcome! Feel free to contact us again!
Hi,

Unfortunately the synchronization functionality does'nt work anymore with your latest example,
try it, if you change the view or manipulate the range selector the other chart does'nt follow and shows the data,
it's just like having 2 independent charts...
It does this even in the jsfiddle dev environment with the link you posted: https://jsfiddle.net/BlackLabel/k8azegtq/
Maybe you forgot to test this sync functionality before you posted it ?
I've tried a few things but can't get it to work, I can get the 2nd chart to move it's rangeslider, but it does'nt sync up properly and goes off in random directions...

Also, in the 2 charts, there are the variables: "pointStart: Date.UTC(2020, 1, 1),",
what does this mean, is this the starting view/range finder, or does it indicate that the data fed into the chart starts at this date ? (the JSON url demo data starts in ~2010)

If we can get this last problem fixed, we're finished... :)

Please can you help with this ?

Thanks, I really appreciate the time you've put into this...
Terrence
radiance32
Posts: 18
Joined: Thu Apr 08, 2021 4:10 am

Re: multiple charts on one page with shared x-axis view/range selection/zoom

Hi,

After playing with it some more, I noticed it's not loading the data anymore when you change the view,
it only uses the very first data that's loaded when the chart is loaded, but when you change the view/zoom in,
the more detailed data is'nt loaded from the JSON url...
So this last example has 2 major issues, no lazy JSON data loading and no synchronization of the view/rangefinder between the charts... :(

Terrence
pawelys
Posts: 962
Joined: Wed Sep 02, 2020 10:37 am

Re: multiple charts on one page with shared x-axis view/range selection/zoom

Hello again! Just crossed my mind, that we have the demo of the exact use case, that you are describing! Check our official Highcharts demo: https://www.highcharts.com/demo/synchronized-charts

and let me know if that works for you! Kind regards,
Paweł Lysy
Highcharts Developer
radiance32
Posts: 18
Joined: Thu Apr 08, 2021 4:10 am

Re: multiple charts on one page with shared x-axis view/range selection/zoom

pawelys wrote: Wed Apr 28, 2021 2:09 pm Hello again! Just crossed my mind, that we have the demo of the exact use case, that you are describing! Check our official Highcharts demo: https://www.highcharts.com/demo/synchronized-charts

and let me know if that works for you! Kind regards,
Hi again,

First of all, thanks again for your time you've put into helping me out, I really appreciate it.
Unfortunately this demo does'nt do what I'm looking for.
It is missing the rangeselector (or whatever it's called, the bar on the bottom you can move/resize to change the position/zoom view of the x axis,
and it also lacks many other things... I've had a look at the code but I've no clue how to even begin modifying it...

We were on the right track with this example you gave me a few posts ago: https://jsfiddle.net/BlackLabel/pfqv5e6s/
That example was exactly what I needed, multiple charts with the view/rangeselector staying in sync accross all charts when you move/resize it, but instead of having a sine wave as data for each chart,
I'd need someone to modify the code to have each chart use it's own JSON URL to load it's data in a lazy fashion from a very large dataset (millions of points) as needed for the view, and reload it when the view/zoom changes just like the "1.7 million candlestick demo", but i'm just using lines and splines, no candlesticks...
Also, I'd need to have to be able to change the variables for each chart manually so i can given them all unique titles, subtitles, etc... So i'd need to have individual sections of javascript code to define the variables for each chart...

Do you understand what I mean or do you want me to make you a photoshop mockup of what i mean ? Maybe that would explain my intentions better...

I'm starting to get really stressed out, i've about a month left to finish this app and this chart stuff is turning into a nightmare... :(

If you could help me out, and modify https://jsfiddle.net/BlackLabel/pfqv5e6s/ so it does what I need,
we're done... :)

Thanks for your time,
Terrence
radiance32
Posts: 18
Joined: Thu Apr 08, 2021 4:10 am

Re: multiple charts on one page with shared x-axis view/range selection/zoom

pawelys wrote: Wed Apr 28, 2021 2:09 pm Hello again! Just crossed my mind, that we have the demo of the exact use case, that you are describing! Check our official Highcharts demo: https://www.highcharts.com/demo/synchronized-charts

and let me know if that works for you! Kind regards,
The following code is what I'm using as a "placeholder" for the moment as it is the closest to what I need.
It does everything I need, except, it does'nt load it's data from a JSON URL, but it just generates sine waves.

Code: Select all

let optionsForFirstChart = {
	rangeSelector: {
		selected: 2
	},

	title: {
		text: 'Heart Rate / Beats per minute'
	},

	subtitle: {
		text: 'Patient: SAL246, Mrs. Jane Watson'
	},

	legend: {
		enabled: true
	},

	plotOptions: {
		series: {
			showInLegend: true
		}
	},

	series: [{
		pointStart: Date.UTC(2020, 1, 1),
		pointInterval: 1000 * 24 * 3600,
		data: Array.from({
			length: 1000
		}, (_, x) => Math.floor(100 * Math.sin(x / 10)))
	}]
};

let optionsForSecondChart = {
	rangeSelector: {
		selected: 2
	},
	chart: {
		type: 'column'
	},
	title: {
		text: 'SpO2 - Blood Oxygen Saturation'
	},

	subtitle: {
		text: 'Patient: SAL246, Mrs. Jane Watson'
	},
	
	legend: {
		enabled: true
	},

	plotOptions: {
		series: {
			showInLegend: true
		}
	},

	series: [{
		pointStart: Date.UTC(2020, 1, 1),
		pointInterval: 1000 * 24 * 3600,
		data: Array.from({
			length: 1000
		}, (_, x) => Math.floor(100 * Math.sin(x / 3)))
	}]
};

let optionsForNextChart = {
	rangeSelector: {
		selected: 2
	},
	chart: {
		type: 'spline'
	},
	title: {
		text: 'Body Temperature (°C)'
	},

	subtitle: {
		text: 'Patient: SAL246, Mrs. Jane Watson'
	},
	
	legend: {
		enabled: true
	},

	plotOptions: {
		series: {
			showInLegend: true
		}
	},

	series: [{
		pointStart: Date.UTC(2020, 1, 1),
		pointInterval: 1000 * 24 * 3600,
		data: Array.from({
			length: 1000
		}, (_, x) => Math.floor(100 * Math.sin(x / 5)))
	}]
};

let optionsFornextnextChart = {
	rangeSelector: {
		selected: 2
	},
	chart: {
		type: 'area'
	},
	title: {
		text: 'ECG (Heart / electrocardiogram)'
	},

	subtitle: {
		text: 'Patient: SAL246, Mrs. Jane Watson'
	},
	
	legend: {
		enabled: true
	},

	plotOptions: {
		series: {
			showInLegend: true
		}
	},

	series: [{
		pointStart: Date.UTC(2020, 1, 1),
		pointInterval: 1000 * 24 * 3600,
		data: Array.from({
			length: 1000
		}, (_, x) => Math.floor(100 * Math.sin(x / 5)))
	}]
};


let optionsForlastChart = {
	rangeSelector: {
		selected: 2
	},
	chart: {
		type: 'bar'
	},
	title: {
		text: 'Sleep Stages'
	},
	
	subtitle: {
		text: 'Patient: SAL246, Mrs. Jane Watson'
	},
	
	legend: {
		enabled: true
	},

	plotOptions: {
		series: {
			showInLegend: true
		}
	},

	series: [{
		pointStart: Date.UTC(2020, 1, 1),
		pointInterval: 1000 * 24 * 3600,
		data: Array.from({
			length: 1000
		}, (_, x) => Math.floor(100 * Math.sin(x / 5)))
	}]
};

let charts = [
	Highcharts.stockChart('container', optionsForFirstChart),
	Highcharts.stockChart('container2', optionsForSecondChart),
	Highcharts.stockChart('container3', optionsForNextChart),
	Highcharts.stockChart('container4', optionsFornextnextChart),
	Highcharts.stockChart('container5', optionsForlastChart)
]

charts.forEach(chart => {
	chart.xAxis[0].update({
		events: {
			afterSetExtremes: function (event) {
				charts.forEach(otherChart => {
					if (otherChart.xAxis[0].min != event.min || otherChart.xAxis[0].max != event.max) {
						otherChart.xAxis[0].setExtremes(event.min, event.max)
					}
				})

			}
		}
	})
});

If someone could modify this code so that each chart loads it's data from it's own JSON URL (a different JSON URL for each chart),
with the "start" and "end" options passed to the JSON server so the server can give a small subset of the many millions of points of data it has for the chart in question. So it has to be loaded "lazy", just like how the data is loaded in the "1.7 million points candelstick demo", except i'm just using x/y value pairs for lines and splines, not candlesticks...

If someone could do this, my charts part of my application will be done and I can move on to hopefully finish it in time...

Thanks for your time,
Terrence
pawelys
Posts: 962
Joined: Wed Sep 02, 2020 10:37 am

Re: multiple charts on one page with shared x-axis view/range selection/zoom

Hi! This demo, that I shared with you (the default one) is perfect for your problem. Check the following demo:
https://jsfiddle.net/BlackLabel/dzvou1es/

And let me break it into steps.
The function syncExtremes allows you, to keep the xAxis extremes synced up (obviously). This function is defined as the xAxis.events.setExtremes callback Function, so it fires every time you change the extremes in any chart.


I don't really know, how are you getting your data, but let's assume, that you are getting it from some kind of ajax call. You can get the data from multiple places, parse it, so it matches the correct format, and define it as the series.data.

There is no more to it, and I think it is impossible to explain it in further detail. Please, if you have any more questions, please, ask a specific question!

Kind regards,
Paweł Lysy
Highcharts Developer

Return to “Highcharts Stock”