I want to show tooltip on mouse hover of every coordinate in angular-highchart, it should show x and y axis value in tooltip or label - highcharts

chart = new Chart({
chart: {
type: "line",
// height : 1000
// height: 55 + '%',
height: (9 / 16) * 100 + "%",
// width: 1200,
},
title: {
text: "",
},
credits: {
enabled: false,
},
legend: {
title: {
text: "OrderNumber",
style: {
fontStyle: BOLD,
},
},
layout: "vertical",
align: "right",
verticalAlign: "top",
borderWidth: 1,
floating: true,
backgroundColor: WHITE,
},
xAxis: {
startOnTick: true,
endOnTick: true,
title: {
text: this.xLabel,
style,
},
type: CTYPE,
gridLineColor: BLACK,
// min:
// this.chartData != undefined
// ? Math.log10(Math.ceil(Math.min(this.chartData.series) / 10) * 10)
// : this.xMin,
max: this.xMax,
gridLineWidth: 1,
lineColor: BLACK,
minorGridLineColor: BLACK,
lineWidth: 1,
tickLength: 20,
tickInterval: 1,
minorTickInterval: 0.1,
minorGridLineWidth: 0.5,
// animation: false,
labels: {
formatter: function () {
var raise = require("superscript-text");
let num = Math.log10(this.value as number).toPrecision(1);
let base = "10";
let final = base + raise(num.toString());
return final;
},
},
},
yAxis: {
startOnTick: true,
endOnTick: true,
title: {
text: this.yLabel,
style,
},
max: this.yMax,
min: this.yMin,
type: CTYPE,
lineColor: BLACK,
lineWidth: 1,
gridLineColor: BLACK,
minorGridLineColor: BLACK,
gridLineWidth: 1,
tickLength: 20,
tickInterval: 1,
minorTickInterval: 0.1,
minorGridLineWidth: 0.5,
labels: {
formatter: function () {
var raise = require("superscript-text");
let num = Math.log10(this.value as number);
let base = "10";
let final = base + raise(num.toString());
return final;
},
},
},
plotOptions: {
series: {
stickyTracking: false,
marker: {
enabled: false,
},
states: {
hover: {
enabled: false,
},
inactive: {
opacity: 1,
},
},
animation: false,
visible: true,
},
line: {
events: {
legendItemClick: function (event) {
this.selectedItemList.forEach((item) => {
if (event.target.options.id === item.product.index) {
item.product.toggleSlashEye = !item.product.toggleSlashEye;
let count = 0;
this.selectedItemList.forEach((item) => {
if (item.product.toggleSlashEye === false) count++;
});
if (count === this.selectedItemList.length) this.isSeriesVisible = true;
else this.isSeriesVisible = false;
}
});
}.bind(this),
},
},
// animation: false,
},
tooltip: {
enabled: true,
followPointer: true,
formatter: function () {
return `<b>x = ${this.y}</b> y = <b>${this.x} </b>`;
},
},
series: [],
});
currnet code status - currently I am showing tooltip on series only.
expected - I want to show the tooltip on the locations where the yaxis and xaxis graph lines cross.

Related

Highcharts. Indentation and formatting issues

I want to make the graph start at 0 (as shown in the picture) and have the string formatted according to the regular expression replace(/\B(?=(\d{3})+(?!\d))/g, " ") but all my attempts are unsuccessful.
chartOptions: {
colors: ['#3DC3FB', '#FF5252', '#D2F449', '#179877'],
title: {
text: "",
},
credits: {
enabled: false
},
tooltip: {
formatter: function () {
if (this.x > 0) {
return this.x;
} else return false;
},
},
plotOptions: {
series: {
enableMouseTracking: false,
states: {
hover: {
enabled: false
},
normal: {
animation: false
},
select: {
enabled: false
}
}
},
},
xAxis: {
gridLineWidth: 1,
tickmarkPlacement: 'on',
lineColor: "#A4A4A4",
min: 0,
categories: [null, "10 лет"],
top: 10,
right: -100,
title: {
style: {
color: "#A4A4A4"
}
},
},
yAxis: {
gridLineWidth: 0,
tickColor: 'undefined',
tickLength: 5,
tickWidth: 1,
tickPosition: 'outside',
lineWidth: 1,
lineColor: '#A4A4A4',
min: 3,
title: {
text: "Доход от инвестиций",
margin: 10,
align: "low",
style: {
color: "#A4A4A4"
},
y: -50,
},
labels: {
enabled: false,
},
},
legend: {enabled: false},
marker: {
enabled: false,
symbol: 'circle',
radius: 12,
states: {
hover: {
fillColor: 'white',
lineColor: 'green',
lineWidth: 0
}
}
},
series: [
{
type: 'line',
name: "ВДело",
data: [0, 1100],
dataLabels: {
x: -100,
y: 5,
enabled: true,
// useHTML: true,
format: `{point.y}/мес`,
formatter: function () {
return Highcharts.numberFormat(this.y,2);
},
color: "#3DC3FB",
style:{
fontSize: 20,
lineHeight: 18,
fontWeight: 500,
fontFamily: 'Gilroy',
fontStyle: 'normal',
}
},
animation: {
defer: 1
},
marker: {
symbol: 'circle',
radius: 4,
states: {
hover: {
fillColor: '#3DC3FB',
lineColor: 'green',
lineWidth: 0
}
}
},
},
{
type: 'line',
name: "Акции",
data: [0, 550],
animation: {
defer: 1
},
marker: {
symbol: 'circle',
radius: 4,
states: {
hover: {
fillColor: '#FF5252',
lineColor: 'green',
lineWidth: 0
}
}
},
},
{
type: 'line',
name: "Облигации",
data: [0, 366],
animation: {
defer: 1
},
marker: {
symbol: 'circle',
radius: 4,
states: {
hover: {
fillColor: '#D2F449',
lineColor: 'green',
lineWidth: 0
}
}
},
},
{
type: 'line',
name: "Депозит",
data: [0, 275],
animation: {
defer: 1
},
marker: {
symbol: 'circle',
radius: 4,
states: {
hover: {
fillColor: '#179877',
lineColor: 'green',
lineWidth: 0
}
}
},
},
],
},
I am new to highcharts and have a hard time with huge documentation. help me please
Understood the cost of his sleep. For those who will be interested. So that the graph starts like in the picture.
plotOptions: {
series: {
findNearestPointBy: 'x',
label: {
connectorAllowed: false
},
pointPlacement: 'on'
}
}
and
{
type: 'line',
name: "ВДело",
data: [0, 1100],
dataLabels: {
x: -50,
y: -10,
enabled: true,
format: `{point.y}/мес`,
pointFormat: ' <b>{point.y:,.0f}/мес</b>',
shared: true,
color: "#3DC3FB",
style:{
fontSize: 20,
lineHeight: 18,
fontWeight: 500,
fontFamily: 'Gilroy',
fontStyle: 'normal',
}
},
When it comes to the place to start the chart in the category axis, you need to only change xAxis.min to 0.5
Sample code:
xAxis: {
min: 0.5,
tickmarkPlacement: 'on',
type: 'category'
},
Simplified demo:
https://jsfiddle.net/BlackLabel/jt1gqrnb/

Scrolling using x axis scrollbar the tooltip is shown at some other place gnatt highcharts

As soon as I scroll using x axis and hover over any bar the tooltip location comes at the end of the chart rather than above the bar.
const chart = Highcharts.ganttChart('container', {
chart: {
spacingLeft: 1,
style: {
fontFamily: ' Roboto, sans-serif;'
},
// event:{
// load: function(e){
// console.log(e)
// }
// },
scrollablePlotArea: {
scrollPositionY: 0,
opacity: 0
}
},
title: {
text: 'Gantt Chart with Navigation'
},
// chart: {
// scrollablePlotArea: {
// minWidth: 700,
// scrollPositionX: 1
// },
// events: {
// click: function(event) {
// alert (
// 'x: '+ Highcharts.dateFormat('%Y-%m-%d', event.xAxis[0].value) +', ' +
// 'y: '+ event.yAxis[0].value
// );
// }
// }
// },
yAxis: {
uniqueNames: true,
grid: {
enabled: true,
borderColor: 'rgba(0,0,0,0.3)',
borderWidth: 1
},
min: 0,
max: 6,
scrollbar:{
enabled : true
},
},
xAxis: {
currentDateIndicator: true,
grid: {
enabled: true,
borderColor: 'rgba(0,0,0,0.3)',
borderWidth: 1
}
},
// tooltip: {
// xDateFormat: '%a %b %d, %H:%M'
// },
plotOptions:{
series: {
pointWidth: 13,
dataLabels: {
enabled: true,
format: '{point.label}',
style: {
cursor: 'default',
pointerEvents: 'none'
}
},
}
},
navigator: {
enabled: true,
liveRedraw: 0,
series: {
type: 'gantt',
pointPlacement: 0.5,
pointPadding: 0.25
},
yAxis: {
min: 0,
max: 3,
reversed: true,
categories: []
}
},
scrollbar: {
enabled: true
},
rangeSelector: {
enabled: true,
selected: 5
},
series: [{
dataLabels: {
enabled: true,
style: {
textOutline: 0
}
},
// name : 'vai',
data: <?php echo $string; ?>
}],
tooltip: {
outside: true,
useHTML: true,
style :{
borderRadius: "10px 10px 10px"
},
pointFormatter: customPointFormatter
}
});

HighCharts chart reloads on initial load

I have a bunch of HighCharts running data from Google Sheets, and some of them firstly render the plot area then keep reloading the data on the chart, and I can't figure out why. Is this just a HighCharts thing, or something I can fix?
This is what's happening https://youtu.be/ddM-WxCAczM
This is the Google Sheet I'm loading into HighCharts cloud https://docs.google.com/spreadsheets/d/e/2PACX-1vSQEXUaZFqT3Oatl3AK8S-bqq6vNs5vDjoG2puaFvQ7LsSGB5dIaBk0Kp2aHWE2lbFEms9gZ6r36TTQ/pubhtml
Here's the custom code I'm applying in HighCharts cloud to render the chart how I need it:
Highcharts.merge(true, options, {
chart: {
height: 445,
marginTop: 70,
spacingBottom:-100,
style: {
fontFamily: '"Trebuchet MS","Trebuchet","Helvetica","Lucida Sans Unicode","Lucida Sans",Tahoma,sans-serif',
},
events: {
load: function () {
this.update({
exporting: {
filename: this.options.title.text,
}
});
}
},
plotBorderColorLeft: '#ccc',
plotBorderWidth: 0,
backgroundColor: {
stops: [
[1, 'rgb(255, 255, 255)'],
]
}
},
plotOptions: {
column: {
pointPlacement: 'between'
},
series: {
marker: {
enabled: false,
},
cursor: 'arrow'
}
},
yAxis: {
plotLines: [{
color: '#010101',
width: 2,
value: 0,
zIndex: 5
}],
lineWidth: 1.5,
gridLineWidth: 0,
lineColor: '#010101',
tickWidth: 1.5,
tickLength: 4,
tickColor: '#010101',
title: {
align: 'high',
offset: -10,
text: '(%)',
rotation: 0,
y: -12,
style: {
fontSize: '14px'
},
},
labels: {
enabled: true,
style: {
fontSize: '13px'
}
},
startOnTick: true,
endOnTick: true,
tickInterval: 1,
tickPosition: 'inside',
tickmarkPlacement: 'on',
},
xAxis: {
title: {
text: 'Date',
style: {
display: 'none'
}
},
offset:-127,
useHTML: true,
labels: {
enabled: true,
rotation: -90,
x: 14,
style: {
fontSize: '16px'
},
y:160
},
lineWidth:2,
lineColor: '#010101',
tickWidth:2,
tickPosition: 'inside',
tickLength:4,
tickColor: '#010101',
tickmarkPlacement: 'on',
startOnTick: false,
endOnTick: false,
min:.0,
max:40.4
},
credits: {
enabled:false
},
legend: {
symbolRadius: 0,
floating:true,
itemStyle: {
font: '14px Trebuchet MS, Trebuchet, "Helvetica", Verdana, sans-serif',
color: '#010101'
},
itemMarginTop: 5,
floating: true,
layout: 'vertical',
align: 'left',
verticalAlign: 'top',
enabled: true,
x: 50,
y: 15
},
subtitle: {
style: {
display: 'none'
},
y: 0
},
title: {
style: {
display: 'none'
},
y: 0
},
tooltip: {
valueSuffix: '%'
},
exporting: {
buttons: {
contextButton: {
enabled: true,
y:-10,
x:10,
text: 'Download',
menuItems: [
"printChart",
"separator",
"downloadPNG",
"downloadJPEG",
"downloadPDF",
"downloadSVG",
"separator",
"downloadCSV",
"downloadXLS",
{
textKey: 'viewData',
text: 'Toggle data table',
onclick: function() {
if (this.dataTableDiv && this.dataTableDiv.style.display !== 'none') {
this.dataTableDiv.style.display = 'none';
} else {
this.viewData();
this.dataTableDiv.style.display = '';
}
}
}
]
}
}
}
});

Highcharts bug - label formatter function does not fire with multiple axis

I have a chart with multiple yAxis and I want to format each one differently. However, it seems with multiple yAxis, the label formatter function does not fire at all. Here's my options:
{
chart: {
backgroundColor: 'transparent',
pinchType: 'none',
height: 320,
events: {
load: (e) => {
}
}
},
plotOptions: {
line: {
states: {
hover: {
enabled: true
}
},
animation: {
duration: 750
}
},
series: {
lineWidth: 2,
}
},
series : [
{ name: 'charts',
type: 'line',
id: 0,
dataGrouping: {
groupPixelWidth: 8
},
},
{ name: 'marketcap',
type: 'line',
id: 1,
color: '#1fd3a3',
dataGrouping: {
groupPixelWidth: 8
},
},
{ name: 'volume',
type: 'area',
id: 2,
color: '#ddd',
lineWidth: 1,
dataGrouping: {
groupPixelWidth: 8
},
}
],
navigator: {
enabled: false
},
scrollbar: {
enabled: false
},
rangeSelector: {
enabled: false
},
// responsive: {
// rules: [{
// condition: {
// maxWidth: 500
// },
// }]
// },
xAxis: {
// crosshair: {
// width: 1,
// color: 'rgba(255,255,255,.5)'
// },
visible: true,
type: 'datetime'
},
yAxis: [
{
opposite: false,
gridLineWidth: 0,
minorGridLineWidth: 0,
height: '75%',
tickAmount: 5,
labels: {
formatter: () => {
// this does not fire
console.log('firing!!');
return this.value
}
}
},
{
opposite: true,
gridLineWidth: 0,
minorGridLineWidth: 0,
height: '75%',
tickAmount: 5
},
{
top: '75%',
height: '25%',
opposite: false,
gridLineWidth: 0,
minorGridLineWidth: 0,
visible: false,
},
],
tooltip: {
followPointer: true,
shared: true,
},
credits: { enabled: false }
}
Notice that I have 3 yAxis, and within each of those I have different keys and values. I need to have a custom format for each, but when I try to use the formatter function, nothing happens. Using the format string value works, but it does not allow me to format the string the way I want. Any ideas?

Highcharts yaxis negative values error

I am using HighCharts to ploot some graph. I want my y-aixs to range between -1 to +1. When i set max=1 and min=-1 for y-axis, it does not work. Is there another way of implementing this. Below is the my code example.
$(opts.containerSelector).find('.chart-container').highcharts({
chart: {
events: {
load: loadLegendSelection
},
},
plotOptions: {
area: {
fillOpacity: 0.7
},
spline: {
marker: {
radius: 3
}
},
series: {
events: {
legendItemClick: storeLegendSelection
}
}
},
legend: {
},
loading: {
labelStyle: { "position": "relative", "top": "45%", "font-weight": "300", "color": "#29303a", "font-size": "22px" }
},
xAxis: {
gridLineDashStyle: 'dash',
gridLineColor: '#c2dce6',
gridLineWidth: 1,
min: minDate,
max: maxDate,
type: 'datetime',
labels: {
formatter: function() {
return formatTimestampTime(this.value);
}
},
events : {
afterSetExtremes : afterSetExtremes.bind(this, opts)
},
minRange: 3600 // one minute
},
yAxis: {
max: 1,
min: -1,
endOnTick: false,
gridLineDashStyle: 'dash',
gridLineColor: '#c2dce6',
gridLineWidth: 1,
labels: {
formatter: function() {
return formatMegawatts(this.value);
}
},
showFirstLabel: false,
title: ''
},
series: convertedData,
exporting: {
enabled: false
},
credits: {
enabled: false
},
tooltip: {
formatter:
function() {
return '<b>' + formatTimestampDateTimeWithSeconds(this.x) + '</b><br>' + formatMegawatts(this.y) + ' ('+ this.series.name + ')';
}
}
});
you can try setting min and max as given below.
yAxis: [{
max:1,
min: -1,
allowDecimals: false,
endOnTick: false,
gridLineWidth: 0,
labels: {
style: {
color: '#767676'
}
},
offset: -10,
title: {
text: 'Inv ' + val_qty,
"textAlign": 'top',
"rotation": 0,
x: 60,
y: yaxisVal,
style: {
color: '#767676',
fontWeight: 'bold'
}
}
}, {
allowDecimals: false,
min: 0,
endOnTick: false,
gridLineWidth: 0,
title: {
text: y2axisname,
"textAlign": 'top',
"rotation": 0,
x: -75,
y: yaxisVal,
style: {
color: '#767676',
fontWeight: 'bold'
}
},
offset: -10,
labels: {
format: '{value}',
style: {
color: '#767676'
}
},
opposite: true
}],

Resources