Showing only one tooltip for all. Highstock highcharts - javascript

I am using highstock module, indicator module and highcharts into my angular application. For example , here's the option of my highstock chart with indicator.
this.stock = new StockChart({
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Stock Price'
},
series: [{
tooltip: {
valueDecimals: 2
},
name: 'AAPL',
id: 'AAPL',
type: 'candlestick',
data: [
[1487635200000, 2354.909912, 2366.709961, 2354.909912, 2365.379883],
[1487721600000, 2361.110107, 2365.129883, 2358.340088, 2362.820068],
[1487808000000, 2367.5, 2368.26001, 2355.090088, 2363.810059],
[1487894400000, 2355.72998, 2367.340088, 2352.870117, 2367.340088],
[1488153600000, 2365.22998, 2371.540039, 2361.870117, 2369.75],
[1488240000000, 2366.080078, 2367.790039, 2358.959961, 2363.639893],
[1488326400000, 2380.129883, 2400.97998, 2380.129883, 2395.959961],
[1488412800000, 2394.75, 2394.75, 2380.169922, 2381.919922],
[1488499200000, 2380.919922, 2383.889893, 2375.389893, 2383.120117],
[1488758400000, 2375.22998, 2378.800049, 2367.97998, 2375.310059],
[1488844800000, 2370.73999, 2375.120117, 2365.51001, 2368.389893],
[1488931200000, 2369.810059, 2373.090088, 2361.01001, 2362.97998],
[1489017600000, 2363.48999, 2369.080078, 2354.540039, 2364.870117],
[1489104000000, 2372.52002, 2376.860107, 2363.040039, 2372.600098],
[1489363200000, 2371.560059, 2374.419922, 2368.52002, 2373.469971],
[1489449600000, 2368.550049, 2368.550049, 2358.179932, 2365.449951],
[1489536000000, 2370.340088, 2390.01001, 2368.939941, 2385.26001],
[1489622400000, 2387.709961, 2388.100098, 2377.179932, 2381.379883],
[1489708800000, 2383.709961, 2385.709961, 2377.639893, 2378.25],
[1489968000000, 2378.23999, 2379.550049, 2369.659912, 2373.469971],
[1490054400000, 2379.320068, 2381.929932, 2341.899902, 2344.02002],
[1490140800000, 2343, 2351.810059, 2336.449951, 2348.449951],
[1490227200000, 2345.969971, 2358.919922, 2342.129883, 2345.959961],
[1490313600000, 2350.419922, 2356.219971, 2335.73999, 2343.97998],
[1490572800000, 2329.110107, 2344.899902, 2322.25, 2341.590088],
[1490659200000, 2339.790039, 2363.780029, 2337.629883, 2358.570068],
[1490745600000, 2356.540039, 2363.360107, 2352.939941, 2361.129883],
[1490832000000, 2361.310059, 2370.419922, 2358.580078, 2368.060059],
[1490918400000, 2364.820068, 2370.350098, 2362.600098, 2362.719971],
[1491177600000, 2362.340088, 2365.870117, 2344.72998, 2358.840088],
[1491264000000, 2354.76001, 2360.530029, 2350.719971, 2360.159912],
[1491350400000, 2366.590088, 2378.360107, 2350.52002, 2352.949951],
[1491436800000, 2353.790039, 2364.159912, 2348.899902, 2357.48999],
[1491523200000, 2356.590088, 2363.76001, 2350.73999, 2355.540039],
[1491782400000, 2357.159912, 2366.370117, 2351.5, 2357.159912]
]
}, {
type: 'sma',
linkedTo: 'AAPL',
params: { period: 5 }
}]
});
}
this code looks like this
If you see, there are two tooltips. One for the candlestick series and another one for SMA series. I want to merge these two tooltips into one in such a way that in one tooltip after open , high , low , close values. SMA series name and the value should come. I tried to do using tooltip formatter but maybe I am missing something so it is not coming in the way I want.

Have you tried to play with the tooltip.shared and tooltip.split parameters? Here is the code:
tooltip: {
split: false,
shared: true
},
Live example: https://jsfiddle.net/s8m90bjt/
API Reference:
https://api.highcharts.com/highstock/tooltip.shared
https://api.highcharts.com/highstock/tooltip.split

Related

How to create Highcharts plotbands along every point in line chart

I want to create a linechart with HighCharts that has a plotband along every point of the line. Like so: https://imgur.com/a/WVj7uJb
(They are using HighCharts as well, so it must be possible).
However, I can't seem to manage getting it for every point specific. Whenever I add plotbands, it just draws a band using the highest and lowest point like so: https://imgur.com/a/PZdKIBz
How I currently render the chart (note the plotbands part):
Highcharts.chart('chart', {
chart: {
type: 'line',
},
title: {
text: `${this.variable}`,
},
credits: {
enabled: false,
},
xAxis: {
type: 'category',
title: {
text: "Date"
},
},
yAxis: {
title: {
text: this.unit
},
plotBands: [
{
color: "orange",
from: 12,
to: 14
},
{
color: "orange",
from: 10,
to: 13
} // and so on.
]
},
tooltip: {
headerFormat: `<div>Date: {point.key}</div>`,
pointFormat: `<div>${this.unit}: {point.y}</div>`,
useHTML: true,
},
series: seriesList,
} as any);
So exact example would render a plotband from 10 to 14 along the whole linechart, instead of to different points: one from 12 to 14, and one from 10 to 13.
Any ideas as to how I can accomplish this? I have seen something with 'path', but I can't find anything about it.
Thanks in advance.
In that case, you should use arearange series instead of plotBand.
Demo:
https://www.highcharts.com/demo/arearange-line
API Reference:
https://api.highcharts.com/highcharts/series.arearange

Highstock Stock Tools Creating Indicator GUI Does Not See Chart Series

I have a chart with several series that have data monthly. I am trying to use the stock tools GUI to enable users to add/alter the SMA indicator. I can get the stock tools to load and have the popup to modify the SMA properties. Except, the GUI has no series listed in the drop down. I have created a very simplified version using unemployment data and just one series here.
I am adding the libraries as per usual and my chart code is nothing fancy. My series looks like:
type: 'line',
name: 'Unemployment Rate (%)',
tooltip: {
valueSuffix: '%',
valueDecimals: 1
},
visible: true,
showInNavigator: true,
data: [{
x: 189406800000,
y: 4.50
},
{
x: 192085200000,
y: 4.30
},
{
x: 194590800000,
y: 3.60
},...
I get no errors in the console - just no way to create the SMA series linked to a series of my choosing. Note that if I manually create the SMA series and link to my data series it does appear but I do not want to create a default ahead of time.
You need to add id property to your series:
series: [{
id: 'one',
data: [...]
}]
Live demo: https://jsfiddle.net/BlackLabel/t91qeu3z/
API Reference: https://api.highcharts.com/highstock/series.line.id

Different X values for different columns on highchart

I have a problem with drawing a highchart like on this fiddle
Sample highchart. But I want chart like this one, but with many series/labels in legend. I want to get 'Jan', 'Feb', 'March', 'April' as a different series to filtering the chart. How can I do that?
When I'm using something like this instead of one series I've got 4 series only for first X value. So it's not a solution.
series: [{
name: 'Series1',
data: [49.9]
}, {
name: 'Series2',
data: [83.6]
}, {
name: 'Sereis3',
data: [48.2]
}, {
name: 'Sereis4',
data: [42.1]
}]
Thanks Sebastian Bochan. Your comment was very helpful.
This is solution of my problem
http://jsfiddle.net/tLjke7fp/6/
I have only added this code to your solution.
plotOptions: {
column: {
stacking: 'normal',
}
},
or
plotOptions: {
column: {
grouping: false,
}
},

Highcharts X-axis labels on the side

I'm using Highcharts, and I used to be able to get labels on the side. But it's not working now, am I missing something? The red arrow is where I would want the labels like in the following example.
http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/bar-basic/
This is the code I'm using, I add the series in a dynamic way.
credits: {
enabled: false
},
chart: {
type: 'bar'
},
xAxis: {
categories: ['Jan', 'Feb'],
labels: {
enabled: true,
}
},
yAxis: {
min: 0,
max: 100,
title: {
text: 'Score',
align: 'high'
}
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
}
});
// Add Series
var detailchart = $('#chart-detail').highcharts();
var categories = new Array;
// Set Chart Title
detailchart.setTitle({text: results[0].category});
$.each(results, function(i, data){
categories.push(data.name);
detailchart.addSeries({
name: data.name,
data: [data.score]
});
});
detailchart.xAxis[0].setCategories(["1", "2"]);
$('#chart-detail').highcharts().reflow();
Results is an array that looks like this (I get it through ajax):
As I understand from your code here, you wish to specify two categories with names 1 and 2 but you are not specifying any data for second category, So the only category that is showing on your chart is 1. Your data array for each series must have elements per each category. For example if you have two category you should consider having two data elements in each series. In this line data: [data.score] you are just specifying one element in data array. Your code should be something like this: (make it dynamic per your need)
$.each(results, function(i, data){
categories.push(data.name);
detailchart.addSeries({
name: data.name,
data: [data.score, 40], //40 is some data for your second category.
});
});
Demo: http://jsfiddle.net/u6crkatv/
Only what you need is use 4 series, each of them with single data point.
series: [{
name: 'Year 1800',
data: [107]
}, {
name: 'Year 1900',
data: [138]
}, {
name: 'Year 2008',
data: [973]
},{
name: 'Year 20098',
data: [973]
}]
Example: http://jsfiddle.net/y9wzggc4/

Highchart ticks start point change when categories names are set

I have a chart made with highcharts.js.
The graph works the way I wanted but then if I try to set the categories (programmatically or not) somehitng strange happen, the tick become smaller and move to the centre leaving a big space on the sides of the graph.
BEFORE:
AFTER:
$(function () {
$('#container').highcharts({
chart: {
renderTo: 'graph',
type: 'area',
},
xAxis: {
title: {
text: ''
},
startOnTick: false,
endOnTick: false,
tickmarkPlacement: 'on',
},
series: [{
data: [['aa',29.9], ['bb',71.5], ['cc',106.4],['dd', 129.2 ]]
}],
});
// the button handler
$('#button').click(function() {
var chart = $('#container').highcharts();
chart.xAxis[0].setCategories(['bb', 'bb', 'cc', 'dd']);
});
});
See this JsFiddle:
http://jsfiddle.net/MaurizioPiccini/d746v/3/
It all happens when you press the button (the categories can be set in the xAxis as well giving the same problem).
Is it possible to have named categories to start and end at the graph extremes?
You can use workaround which, updatse your axis with defined min/max value.
chart.xAxis[0].update({
categories: ['bb', 'bb', 'cc', 'dd'],
min: 0.5,
max: 2.5
});
http://jsfiddle.net/d746v/6/
I found a solution that is also reporteed here:
http://forum.highcharts.com/highcharts-usage/highchart-ticks-start-point-change-when-categories-names-are-t29052/
The solution is not to use categorized xAxis but linear or datetime with label formatter like this:
xAxis: {
labels: {
formatter: function(){
return categories[this.value];
}
}
}
where categories is an array of categories.
It looks like that is the only way to make the chart behave this way.

Categories

Resources