Highcharts, obtain json/serialized chart object options? - highcharts

i need to do something, i tried everything but i cannot get what i want.
I have one chart in one container, and at some point a have to render that chart to another div, but without losing the first one, so... i need to duplicate that chart but in a new container.
Im able to get the chart that im refering to, but i need something like getting the options of this chart so i can initialize another chart, with same options but in a different container.
The chart is generated dinamically, so i do not have the options before it is rendered, so the only way i can get the option in order to replicate the chart i getting the options of an already painted chart.
Is there any way to achieve that?
Thank you.

You can use chart.userOptions property to get the options needed to create a second chart:
var chart = Highcharts.chart('container', {
series: [{
type: 'column',
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
}],
xAxis: {
max: 10
}
});
$('#duplicate').on('click', function() {
Highcharts.chart('container2', chart.userOptions);
});
Live demo: http://jsfiddle.net/BlackLabel/9q70mvky/

Related

Highcharts: SeriesMapping with CSV

I have a chart that works very well when using the data module with Google spreadsheets. However I need to stop using Google sheets and use CSV on my own server instead. Some of my charts are working, but some aren't. Here's one that is not working. It uses the second column to set the point color, but it's not recognizing it. Any idea what might be wrong here? I edited some of the csv entries to try to make it work, but it's not working much:
http://jsfiddle.net/jmunger/cf6L4bmk/20/
var chart = Highcharts.chart('gfx', {
chart: {
type: 'bar',
},
data: {
csv: document.getElementById('csv').innerHTML,
itemDelimiter: ',',
seriesMapping: [{
color: 2,
label: 3
}]
}
});
console.log(chart);
That problem seems to be a bug in a data module, so I reported it here: https://github.com/highcharts/highcharts/issues/13283
As a workround you can use other color formats:
0;1;blue
1;2;rgb(155,155,55)
2;3;red
Live demo: http://jsfiddle.net/BlackLabel/0gjbn4m6/1/

Highcharts, type: 'mapbubble' causes an error 17

When I am using the mapbubble I get an error 17
without it I see the map fine but of course no bubbles on the map :(
the data is
series : [{
name: 'Countries',
mapData: mapData,
color: '#E0E0E0',
enableMouseTracking: false
}, {
type: 'mapbubble',
name: 'Population 2013',
data: data,
maxSize: '12%',
mapData: mapData
}]
and again, if I remove mapbubble I see the map, but with the type, I receieve error 17
tx for any assistance
regards
Sean
'mapbubble' is Highmaps series type. For Highcharts use 'bubble'. You will need to load highcharts-more.
Demo: http://www.highcharts.com/demo/bubble
Error 17 means:
The requested series type does not exist
This error happens when you are setting chart.type or series.type to a
series type that isn't defined in Highcharts. A typical reason may be
that your are missing the extension file where the series type is
defined, for example in order to run an arearange series you need to
load the highcharts-more.js file.
Is it possible that you have highcharts-more.js missing?
Check this SO answer: HighCharts and Map Bubble are not compatible

Highcharts tooltip not showing on unsort data

I have a unsort data (on x-axis) and using Highcharts to display the graph. I knew the x-axis must sort to show the tooltip as the Highcharts document wrote. But my data could not be sorted by some reasons, so could anyone meet this problem before, please give any idea/solution to show the tooltip without sort x-axis data. If I sort, my data will be wrong.
My js:
var data = [
[5.875, -20],
[8.1875, -30],
[8.875, -40],
[9.5, -50],
[10.125, -60],
[10.5, -70],
[10.875, -80],
[11.375, -90],
[11.6875, -100],
[11.875, -110],
[12.0625, -120],
[12.625, -130],
[12.4375, -140],
[12.625, -150],
[12.5, -160],
[12.4375, -170],
[12.4375, -180],
[12.375, -190],
[12.25, -200],
[12.1875, -210],
[11.9375, -220],
[11.625, -230],
[11.5, -240],
[11.125, -250],
[10.75, -260],
[10.625, -270]
];
$('#container').highcharts({
series: [{
data: data
}]
});
Or please check here http://jsfiddle.net/vuong/jedLowyv/4/
Thank you so much and have a nice day.
You have two options:
sort your data: http://jsfiddle.net/jedLowyv/5/
use scatter series with lineWidth: http://jsfiddle.net/jedLowyv/6/ (not: tooltip will show up only when hover one of markers directly)

Highcharts cannot read property 'series' of undefined

I'm seeing this error when I create a line chart with a single y-axis.
Uncaught TypeError: Cannot read property 'series' of undefined highcharts.3.0.1.js:147
It seems that the series is a bit displaced to the left. The leftmost tool tip is hanging off the chart where the y-axis names are showing. All the tooltips are off a bit and if I mouse all the way to the right of the chart I see this error over and over in the console.
Interestingly, if I zoom in and then hit the 'reset-zoom' the chart renders properly and the problem goes away.
unfortunately, creating a fiddle will be hard as I build my config options on the fly. I am using addSeries to add my series to an empty chart once it has been displayed.
Thanks in advance for any help or tips.
-Dale
In general, without code it is really hard to find issue, just copy your 'options on the fly' which reproduce issue, please.
However, most probably you are trying to add series for axis, which doesn't exists. For example:
yAxis: { },
series: [{ yAxis: 1 }] <-- obviously there is only one yAxis
export class xyzComponent implements OnInit {
highcharts = Highcharts;
chart;
chartCallback;
title = 'myHighchart';
chartConstructor = "chart";
chartOptions: {};
ngOnInit() {
this.chartOptions = {
chart: {
type: "spline"
},
title: {
text: 'Average Vegetation and Soil Moisture Index'
},
}
}
}
it's for Angualar

Highstock Navigator always starts from 1970-1-1

I have problem with Highstock navigator always displaying 1970-1-1 as a start point when creating dynamic series and data... does anyone have encountered this issue and has some workarounds?
Here is an example: http://jsfiddle.net/sokarovski/SRtvn/
var $container = $('.canvas');
var chart = new Highcharts.StockChart({
chart: {
renderTo: $container[0]
},
xAxis: {
type: 'datetime' ,
ordinal: false
}
});
chart.addSeries({
data: [
[Date.UTC(2013,1,1), 0],
[Date.UTC(2013,1,5), 10],
[Date.UTC(2013,1,15), 15],
[Date.UTC(2013,2,5), 20],
[Date.UTC(2013,2,28), 25],
[Date.UTC(2013,3,3), 30],
]
});
//I tried to fix it with this also but it does not help
chart.xAxis[0].setExtremes(Date.UTC(2013,1,1), Date.UTC(2013,3,3));
It is caused, that navigator doesn't work properly, when you try to addSeries / addPoint to chart which have no series / data. This bug is reported here:
https://github.com/highslide-software/highcharts.com/issues/624
What we do is we pre-fetch our data we want to add to the chart and take the first point and create a series on the stock chart with just that one point. We then call the add data code to add the rest of the points such that the chart "plays".
Now, if you do not know what data you are going to get first (for example you let the user click a button to show data1 or data2 and you do not have a default) you can create your chart - but hide it. By using the loading options. So, you create an empty chart and do not show it until such time the user has selected the data.

Resources