I have a line chart that plots multiple datasets where each dataset has two lines associated with it: a reference line and a measured line.
To plot all of these lines, I added individual series for each subset of data, giving the reference line a dashed appearance and the measured line a solid appearance.
The tooltip formatter displays a popover of detail data for a specific point based on the cursor position. It only displays data for one series.
How might I group the series together in such a way that I can display a tooltip for multiple series, but not necessarily all of the series?
Highcharts seems to have an option for shared that displays a tooltip for all of the series that correspond to the cursor's X coordinate, but is there a way to do some sort of grouping? Is there something I can do to the series configuration so that each series renders two lines on the chart but with different appearances?
Not sure if what I'm trying to do is possible with Highcharts. Might need to be a custom chart.
There is no such default functionality in Highcharts, but for now I see two possible workarounds:
slight change in x value:
series: [{
data: [1, 1, 1]
}, {
data: [[0.0001, 2], [1.0002, 2], [2.0002, 2]]
}, {
data: [3, 3, 3]
}, {
data: [[0.0001, 4], [1.0002, 4], [2.0002, 4]]
}]
Live demo: http://jsfiddle.net/BlackLabel/v1uxp3jh/
wrap of the refresh method to exclude some of the unwanted points:
(function(H) {
H.wrap(H.Tooltip.prototype, 'refresh', function(proceed, points) {
points.forEach(function(p, i) {
if (p.series.name === "Series 2") {
points.splice(i, 1);
}
});
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
});
}(Highcharts));
Live demo: http://jsfiddle.net/BlackLabel/qd4mnx8e/
Docs: https://www.highcharts.com/docs/extending-highcharts
Related
I have a sparkline chart of temperature sensor data,
Its a year of data sampled at every 1 min
I first load a blank chart, then I do a server call, bring the results back and display it by calling
getchart.addSeries({
name: thisGroup,
id: probeItem[0],
data: probeDataArray,
keys: ['x', 'y', 'specialId'],
there could be upto 20 series, and they all load on the screen one by one
This renders quite quickly, however I now need to add a label annotation where the temperature goes over a certain Value (i.e. in add a warning symbol when its alarm state)
Currently I'm looping through each point and seeing if its over a certain value:
currentSeries.points.forEach(function (point) {
However this is very slow.
I have an array of the alarms, and can reference them as
['x', 'y', 'specialId']
However I cannot see how I can add an annotation label by x,y or specialId.
I can only seem to add the label if i loop through all the points already rendered
Is there a way to add a label by using my Id's?
I also need to resize the graph and the labels to remain in the same place
Alternatively if this is not possible, is there anyway to add the labels as i'm adding the series?:
getchart.addSeries({
name: thisGroup,
id: CurrentGroupID,
dashStyle: 'ShortDot',
data: groupLogArray,
keys: ['x', 'y', 'specialId'],
showInNavigator: true, //this shows the series data in the small bottom navigator
point: {
events: {
click: function () {
//alert("test click");
}
}
}
});
You can add an annotation by x and y axis values:
chart.addAnnotation({
labels: [{
text: 'Alarm',
point: {
x: 2,
y: 3,
xAxis: 0,
yAxis: 0
}
}]
});
Live demo: http://jsfiddle.net/BlackLabel/k6trha3e/
API Reference: https://api.highcharts.com/class-reference/Highcharts.Chart#addAnnotation
As an alternative, you can also use data labels: http://jsfiddle.net/BlackLabel/n4586xzq/
i want to draw the line by the order of data. Data is added dynamically so i am using addPoint. for example i have this:
let data = [[1,2], [5,3], [2,5]]
chart.series[0].addPoint(data[0])
chart.series[0].addPoint(data[1])
chart.series[0].addPoint(data[2])
and the result is that all the points on the chart are connected sequentially.
but i want it to be like this:
I made that chart by setData, but creating a separate array and repeatedly calling setData seems to be not the correct way. is there a way to achieve that with addPoint? or any other solution?
You can use scatter series type with lineWidth property:
let data = [
[1, 2],
[5, 3],
[2, 5]
]
let chart = Highcharts.chart('container', {
series: [{
type: 'scatter',
lineWidth: 2,
data: []
}]
});
chart.series[0].addPoint(data[0]);
chart.series[0].addPoint(data[1]);
chart.series[0].addPoint(data[2]);
Live demo: http://jsfiddle.net/BlackLabel/ynrkq40g/
API Reference: https://api.highcharts.com/highcharts/series.scatter.lineWidth
i have a highchart with 4 series. I also only set the min value for each y-axis to 0 cause there arent any negative values possible. now highchart is calculating the max value by itself what is nice BUT i need this for each series itself. The reason is that i have 2 series with very high values from the range up to 5000 and the other two values are relativ small from 0 to 50.
The max value highcharts calculates is used for all four series - so the chart looks like this:
As you can see you can only see the two high value series - the other two arent really visible at the bottom of the chart.
When i disable the two series with the high values the chart looks nice for the other two values:
is there any flag i can use so highchart will calculate the max value / scale per series? Or have i really calculate it by myself - also on zoom and so on.
I found this: https://github.com/highcharts/highcharts/issues/4248
But i thought thats some basic functionality with is needed very often so there has to be something..
greetings
Maybe it would be better to use logarithmic axis type? Your chart would have only one axis adjusted to much difference between the values of series points. When it comes to differences between units of measurement, always you can set the different tooltip.pointFormat definition for specific series.
Highcharts.chart('container', {
title: {
text: 'Logarithmic axis demo'
},
yAxis: {
type: 'logarithmic',
},
series: [{
data: [1, 20, 30, 22, 16, 32, 45, 24, 11, 2],
pointStart: 1,
tooltip: {
pointFormat: '<b>{point.y} km/h</b>'
}
}, {
data: [4500, 3450, 4242, 2348, 5216, 3212, 4564, 3128, 5256, 4512],
pointStart: 1,
tooltip: {
pointFormat: '<b>{point.y} kW/h</b>'
}
}]
});
Live example: https://jsfiddle.net/bfnj4mp8/
API Reference:
https://api.highcharts.com/highcharts/yAxis.type
https://api.highcharts.com/highcharts/series.line.tooltip.pointFormat
I have data of the form ["10.237.77.82","10.237.79.255"] which I would like to plot on a scatter plot.
Highchart crashes with error 14: String value sent to series.data, expected Number, which is correct as my data are indeed strings.
Is there a way to use strings as the elements of a scatter plot?
In short, values must be numbers. However, dataset looks like a categorized one, then maybe you just need this: http://jsfiddle.net/BlackLabel/8hc7Lzyu/1? As you can see, categories (IP's) are on axes, but markers are numbers.
Snippet:
Highcharts.chart('container', {
xAxis: {
categories: ["10.237.77.82", "10.237.79.255"]
},
yAxis: {
categories: ["10.237.77.82", "10.237.79.255"]
},
series: [{
data: [
[0, 1],
[1, 0]
]
}]
});
I am trying to create a scatter plot where when you select a point it will create a new graph with different data. This works fine.
The issue is when you zoom in on the second scatter plot then press reset zoom, the chart resizes and pushes all the data to the left (I'm assuming because all my data points have the same x coordinate or because the values are very small). I thought by using setExtremes() the reset zoom would use those values as the min and max.
Here's the JSFiddle: http://jsfiddle.net/kzBxB/5/
Below is the function I'm using to create the new chart. Do I need to change anything to make the 'reset zoom' register my given xAxis min and max values?
function newPoints() {
var chart = jQuery('#container').highcharts();
for (var i = 0; i < chart.series.length; i++) {
serie = chart.series[i];
//sets the new x axis and new data
chart.yAxis[0].setExtremes(0, 10);
chart.xAxis[0].setExtremes(.001, .003);
chart.addSeries({
type: 'scatter',
name: serie.name,
data: [
[.002, 1],
[.002, 2],
[.002, 3],
[.002, 4],
[.002, 5][.002, 6]
]
}, false);
//removes the old series
serie.remove(false);
}
//redraws the chart
chart.redraw();
}
The problem is that all values have the same x-value, so Highcharts don't know where to plot them (what is the range of points). In such case I advice to use afterSetExtremes event:
xAxis: {
events: {
afterSetExtremes: function(e){
if(e.min === e.max){
this.setExtremes(.001, .003);
}
}
}
},
And example: http://jsfiddle.net/kzBxB/7/