Bind highcharts chart to another series - highcharts

I'm trying to change chart series and redraw it.
var newSeries = [1,2,3,4,5]
$('#miniChart').highcharts(
{
series:[data:newSeries]
}
)
Doesnt work

You syntax isn't correct. Should be:
var newSeries = [1,2,3,4,5];
$('#container').highcharts({
series: [{
data: newSeries
}]
});
If you already have a chart, though, and just want to change the data of a series, you'd be better off using the setData method of the series object.
var newSeries = [1,2,3,4,5];
var chart = $('#container').highcharts();
chart.series[0].setData(newSeries);
Here's a fiddle showing both ways.

Related

Drilldown event in Highcharts column chart

In this Highcharts column chart the user can drill down by clicking on the column.
This works fine, however all the data, including the data of the drilled column, needs to be available when the chart is firstly created.
What I need is to capture the drilldown event click and populate the chart with that information, sending the data only when the user clicked on a specific column. Is this possible?
Yes, it is possible and simple. You need to use drilldown event callback function, call API request in it and use addSeriesAsDrilldown method - as in the example below:
chart: {
type: 'column',
events: {
drilldown: function(e) {
if (!e.seriesOptions) {
var chart = this,
drilldowns = {
...
},
series = drilldowns[e.point.name];
// Show the loading label
chart.showLoading('Simulating Ajax ...');
setTimeout(function() {
chart.hideLoading();
chart.addSeriesAsDrilldown(e.point, series);
}, 1000);
}
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/e9m74kgp/
API Reference:
https://api.highcharts.com/highcharts/chart.events.drilldown
https://api.highcharts.com/class-reference/Highcharts.Chart#addSeriesAsDrilldown

Is it possible to define custom technical indicators, that takes 2 series as input?

I have a highstocks chart that shows trends of non stock data because it has some good features that our product needs.
one of these features is custom technical indicators, espcially between 2 different trends showing.
I know how to define maually an indicator, but it seems I can't use more then 1 series with it, while I want to create indicators for a veraity of differneces between 2 or more series.
I can't find a way to do this, so I'm wondering if it is at all possible
Average between two series can be simply added as another separate series. You can use for example load event to calculate it and chart.addSeries() method to add it.
Code:
chart: {
zoomType: 'xy',
events: {
load: function() {
var chart = this,
dataLen = chart.series[0].points.length,
newSeries = {
id: "avg",
name: "average",
data: []
},
series1 = chart.series[0],
series2 = chart.series[1],
i;
for (i = 0; i < dataLen; i++) {
newSeries.data.push({
x: series1.points[i].x,
y: (series2.points[i].y + series1.points[i].y) / 2
})
}
chart.addSeries(newSeries);
}
}
}
Demo:
https://jsfiddle.net/BlackLabel/15sa38qb/
API:
https://api.highcharts.com/highcharts/chart.events.load
https://api.highcharts.com/class-reference/Highcharts.Chart#addSeries

How to programmatically set selection Highchats master-detail chart?

I have created my own master-detail chart following the Highcharts docs and this example: https://www.highcharts.com/demo/dynamic-master-detail
Eveything works fine but I would like to add a feature: When the chart is loaded the last 50 data points should automatically be selected in the master chart and thus shown in the detail chart.
I tried to manually trigger the selection event but it did not work out. Any idea how to solve this?
You can fire selection event in chart load event and set correct extremes:
chart: {
...
events: {
load: function() {
var points = this.series[0].points,
xAxis = this.xAxis[0];
Highcharts.fireEvent(this, 'selection', {
xAxis: [{
min: points[points.length - 51].x,
max: points[points.length - 1].x
}],
});
},
selection: function(event) {
...
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/xy8qug9h/
API: https://api.highcharts.com/highcharts/chart.events.load

Highstock. prevent gaps adding new line series

I want to draw a line on a ohlc chart, but i dont want the new series to introduce gaps.
The first series (ohlc) should still place the candles in an nica way with constant gaps between them regardles of open-close times (i think its only the "ordinal" value that does this, but unfortunatelly you cant specify it at series level, but only axis level).
xAxis: {
ordinal: true
},
example:
http://jsfiddle.net/5r97owky/8/
Thank you for any help
The gaps are caused by ordinal option. You can create additional xAxis for line series:
Highcharts.stockChart('container', {
chart: {
events: {
load: function() {
var xAxes = this.xAxis,
extremes = xAxes[0].getExtremes();
xAxes[1].setExtremes(extremes.min, extremes.max, true, false);
}
}
},
xAxis: [{}, {
visible: false
}],
...
});
Live demo: http://jsfiddle.net/BlackLabel/1mbo2zp4/
API: https://api.highcharts.com/highstock/xAxis.ordinal

individual point settings in a scatter/line plot

In a scatter HighCharts plot, I want to set some properties only for some data points of my series. Here is a toy example:
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
series: [{
type: 'line',
data: [[1,1],
{x:3,y:2,marker:{enabled:false}},
[4,1]]
}]
});
});
});
I need (in decreasing order of priority) the second point to NOT have:
the marker (already done in my code, working);
the tooltip (tried but without success, I don't know how to do it working)
the line coming from previous point (tried but without success, I don't know
how to do it working)
Here is a jfiddle version.
For your second point, improvised from a similar answer:
Disable tooltip on certain points in Highcharts
tooltip: {
formatter: function() {
if (this.point.x != 1) { //enable for each point except the second point
return this.x;
}
else return false;
}
}
for your third point you might try to use a trick. If you set the y value as null, that point won't be displayed in the line. So draw your line, and enter two data with null y values to create a lonely point on the chart.
Here is an example: http://jsfiddle.net/8U8nx/14/

Resources