HIghcharts Legend - highcharts

Is there a way for me to display legends in highcharts just by creating name and its color as a separate data?
If this is my data:
[{
"x": 0.92,
"y": 1.12,
"date": "05-18-2003",
"color": "#0082c8",
"idNo": 3,
"mc": "green",
"symbol": "circle"
},
{
"x": 0.92,
"y": 1.13,
"date": "05-18-2003",
"color": "#0082c8",
"idNo": 10,
"mc": "green",
"symbol": "circle"
},
{
"x": 0.96,
"y": 1.05,
"date": "06-10-2003",
"color": "#f58231",
"idNo": 3,
"mc": "green",
"symbol": "circle"
},
{
"x": 0.96,
"y": 1.09,
"date": "06-11-2003",
"color": "#911eb4",
"idNo": 3,
"mc": "green",
"symbol": "circle"
},
{
"x": 0.96,
"y": 1.1,
"date": "06-11-2003",
"color": "#911eb4",
"idNo": 10,
"mc": "green",
"symbol": "circle"
}
]
and the legend data that I created dynamically based on the above data is
legendData=
[{name: "05-18-2003", color1: "#0082c8"}
{name: "06-11-2003", color1: "#f58231"}
{name: "06-10-2003", color1: "#911eb4"}]
How can I make legend from this legendData variable?
Thanks.

To modify legend item labels you can use labelFormatter function. As for the different color for each legend item, you can use styled mode and style them using CSS. Take a look at the example posted below.
DOCS Reference:
https://www.highcharts.com/docs/chart-design-and-style/style-by-css
API Reference:
http://api.highcharts.com/highcharts/legend.labelFormatter
Example:
http://jsfiddle.net/mw06ywvp/

Related

Highchart-export-server not showing plot band correctly on chart

Plot bands in highchart export server is not working properly. I want the output same as shown in jsfiddle below.
I want the color plot band to show on y axis with width 20.
This is expected output: https://jsfiddle.net/vc6r8y3n/
Attached image is actual output when we use high-chart export server.
but when I tried same JavaScript json object on
http://export.highcharts.com/
its giving me image with plot band color spread on whole chart. its not considering width for 'y' or 'x' axis in export server. I gave attached image of export chart.
Why highchart behaving differently in both the cases.
Highchart JSON is same as in JSfiddle.
Actual image.
Expected is what it display in Jsfiddle. https://jsfiddle.net/vc6r8y3n/
{
"chart": {
"height": 350,
"width": 600,
"style": {
"fontFamily": "\"Arial\", sans-serif",
"fontSize": "16px"
},
"backgroundColor": "transparent"
},
"title": {
"text": null
},
"credits": {
"enabled": false
},
"legend": {
"align": "center",
"layout": "horizontal",
"verticalAlign": "bottom",
"symbolHeight": 5,
"symbolWidth": 5,
"symbolRadius": 0,
"itemDistance": 10,
"itemStyle": {
"fontSize": "5px",
"fontWeight": "bold",
"fontFamily": "\"Arial\", sans-serif"
},
"borderWidth": 0,
"padding": 0,
"margin": 5
},
"xAxis": {
"categories": [
"Sep-2020",
"Oct-2020",
"Nov-2020",
"Dec-2020",
"Jan-2021",
"Feb-2021"
],
"labels": {
"style": {
"fontSize": "4px",
"fontFamily": "\"Arial\", sans-serif",
"color": "#000"
},
"y": 5
},
"gridLineColor": "transparent",
"gridLineWidth": 0,
"minorGridLineWidth": 0,
"lineColor": "#9A9A9A",
"zIndex": 9999999
},
"yAxis": [
{
"title": {
"text": ""
},
"min": 0,
"max": 100,
"tickInterval": 20,
"plotBands": [
{
"color": "rgb(204,0,0)",
"from": 0,
"to": 30.99,
"zIndex": 3
},
{
"color": "rgb(226,113,113)",
"from": 31,
"to": 44.99,
"zIndex": 3
},
{
"color": "rgb(247,209,34)",
"from": 45,
"to": 54.99,
"zIndex": 3
},
{
"color": "rgb(136,207,136)",
"from": 55,
"to": 68.99,
"zIndex": 3
},
{
"color": "rgb(68,180,68)",
"from": 69,
"to": 87.99,
"zIndex": 3
},
{
"color": "rgb(0,153,0)",
"from": 88,
"to": 100,
"zIndex": 3
}
],
"width": 20
}
],
"plotOptions": {
"column": {
"dataLabels": {
"enabled": true
}
}
},
"series": [
{
"name": "Line1",
"type": "column",
"data": [
{
"y": 61,
"color": "#5b9bd5"
},
{
"y": 41,
"color": "#5b9bd5"
},
{
"y": 21,
"color": "#5b9bd5"
},
{
"y": 81,
"color": "#5b9bd5"
},
{
"y": 31,
"color": "#5b9bd5"
},
{
"y": 71,
"color": "#5b9bd5"
}
],
"color": "#5b9bd5",
"showInLegend": true
},
{
"name": "Line 2",
"type": "column",
"data": [
null,
null,
null,
null,
null,
1
],
"color": "#00B050"
},
{
"name": "Line 3",
"type": "spline",
"data": [
null,
{
"y": 45
},
{
"y": 38
},
{
"y": 32
},
{
"y": 40
},
{
"y": 48
}
],
"color": "#9A0229"
}
]
}
enter image description here

highcharts multiple marker hover color doesn't inherit from marker color

I have highchart series data like this to have multiple dot on a column:
series: [{
"marker": {
"fillColor": "#69B0E0",
"symbol": "circle"
},
"type": "line",
"data": [
6000,
5500,
]
},
{
"marker": {
"fillColor": "#333f48",
"symbol": "circle"
},
"type": "line",
"data": [
1000,
4000,
]
},
{
"marker": {
"fillColor": "#b61f47",
"symbol": "circle"
},
"type": "line",
"data": [
11000,
3000,
]
}
]
but when I hover it, the red radius color is green instead of red, but other 2 colors are fine, I wonder is this a bug on highcharts.
demo: https://jsfiddle.net/a0e9bz8k/1/
The hover color is inherited from point.color or series.color, so you need to set one of them.
series: [...,
{
"marker": {
"symbol": "circle"
},
color: "#b61f47",
...
}
]
Live demo: https://jsfiddle.net/BlackLabel/p0h6eqk3/
API Reference: https://api.highcharts.com/highcharts/series.scatter.color

Make minPointLenght apply to all blocks in stacked column chart

We're using minPointLength property to make points with a value of 0 show up in a stacked column chart. The problem is that now a point with a value of 4 (third column from left in screenshot) is displayed smaller than the minimum height. In the following screenshot the very tiny block with value 4 is hovered and the blocks with 0 are displayed in red.
I expected that blocks with a value bigger than 0 are also bigger than the blocks with a value of 0 or at least same height.
Our overall target is to set a minimum height for all blocks, in a way that all the box labels can be shown.
Here is a fiddle to play around: https://jsfiddle.net/ftmkxdbo/
This is the configuration of our chart:
Highcharts.chart('container', {
"chart": {
"type": "column"
},
"title": {
"text": ""
},
"credits": {
"enabled": false
},
"xAxis": {
"categories": ["10/17", "10/18", "10/19", "10/20"]
},
"yAxis": {
"title": {
"text": ""
},
"stackLabels": {
"enabled": true,
"style": {
"color": "gray"
}
},
"min": 0,
},
"legend": {
"enabled": false
},
"plotOptions": {
"column": {
"stacking": "normal",
"dataLabels": {
"enabled": true,
"style": {
"fontSize": "10px",
"fontWeight": "normal",
"textShadow": "0px"
},
},
"minPointLength": 5,
}
},
"series": [{
"name": "3",
"data": [{
"x": 0,
"y": 3,
}],
"index": 0,
"color": "rgba(120,185,40,0.8)"
}, {
"name": "12",
"data": [{
"x": 0,
"y": 12,
}],
"index": 1,
"color": "rgba(245,155,0,0.8)"
}, {
"name": "19",
"data": [{
"x": 0,
"y": 19,
}],
"index": 2,
"color": "rgba(120,185,40,0.8)"
}, {
"name": "13",
"data": [{
"x": 0,
"y": 13,
}],
"index": 3,
"color": "rgba(120,185,40,0.8)"
}, {
"name": "18",
"data": [{
"x": 1,
"y": 18,
}],
"index": 0,
"color": "rgba(120,185,40,0.8)"
},
// ...
]
});
That is a very problematic issue. Currently the columns overlap because the stacking functionality does not take into account the minPointLength option. If it were otherwise, the total value of the column would be incorrect.
You can see all discussion about this problem on github: https://github.com/highcharts/highcharts/issues/1776

Show ticks on x axis in local time with highcharts api

I have a line chart with a date/time x axis. The points have a name that is converted to local time. However, the tick marks are placed at UTC midnight. How can I get them to be placed at local midnight?
To clarify, my localtime is EDT (-04:00). So, at approximately 20:00, the tick mark is shown.
var chart = Highcharts.chart('container', {
"chart": {
"type": "line",
"height": 300,
"marginLeft": 60,
"marginRight": 0,
"spacingLeft": 0,
"spacingRight": 0,
"style": {
"fontSize": 14
},
"zoomType": "x"
},
"tooltip": {
"pointFormat": "{point.y}",
"style": {
"fontSize": 14
}
},
"exporting": {
"enabled": false
},
"title": {
"text": "",
"style": {
"display": "none"
}
},
"subtitle": {
"text": "",
"style": {
"display": "none"
}
},
"legend": {
"enabled": "false"
},
"xAxis": {
"type": "datetime",
"labels": {
"enabled": true,
"style": {
"fontSize": "12px"
}
},
"title": {
"text": null
},
"minTickInterval": 86400000
},
"plotOptions": {
"line": {
"color": "#33aaee",
"step": "true",
"lineWidth": 1
}
},
"credits": {
"enabled": false
},
"series": [{
"data": [{
"x": 1499935040582,
"y": 600.8919674194846,
"name": "Jul 13, 2017 4:37 AM"
}, {
"x": 1500069665426,
"y": 600.3026594460489,
"name": "Jul 14, 2017 6:01 PM"
}, {
"x": 1500133689471,
"y": 600.7274040373635,
"name": "Jul 15, 2017 11:48 AM"
}, {
"x": 1500197550895,
"y": 600.1197607401385,
"name": "Jul 16, 2017 5:32 AM"
}, {
"x": 1500224766324,
"y": 600.2311428390589,
"name": "Jul 16, 2017 1:06 PM"
}, {
"x": 1500247544551,
"y": 600.5511455212492,
"name": "Jul 16, 2017 7:25 PM"
}, {
"x": 1500282216949,
"y": 600.2677789206001,
"name": "Jul 17, 2017 5:03 AM"
}, {
"x": 1500285249151,
"y": 600.3165520296044,
"name": "Jul 17, 2017 5:54 AM"
}, {
"x": 1500472917987,
"y": 600.6858600814295,
"name": "Jul 19, 2017 10:01 AM"
}, {
"x": 1500479945476,
"y": 600.6974345877289,
"name": "Jul 19, 2017 11:59 AM"
}],
"showInLegend": false,
"allowPointSelect": true
}]
});
Here is a fiddle showing this.
Highcharts fiddle
Change you epoch's to a javascript date [new Date(epoch)] this will have the date/time fields show in local time instead of UTC.
"series": [{
"data": [{
"x": new Date(1499935040582),
"y": 600.8919674194846
}, {
"x": new Date(1500069665426),
"y": 600.3026594460489
}, {
"x": new Date(1500133689471),
"y": 600.7274040373635
}, {
"x": new Date(1500197550895),
"y": 600.1197607401385
}, {
"x": new Date(1500224766324),
"y": 600.2311428390589
}, {
"x": new Date(1500247544551),
"y": 600.5511455212492
}, {
"x": new Date(1500282216949),
"y": 600.2677789206001
}, {
"x": new Date(1500285249151),
"y": 600.3165520296044
}, {
"x": new Date(1500472917987),
"y": 600.6858600814295
}, {
"x": new Date(1500479945476),
"y": 600.6974345877289
}],
This should keeps your chart in scale with your local time zone
Found an answer to my problem. I am using moment.js to format the time data, so I changed it from:
chart.series[0].data.push({ x: moment(grp.Time).format('x'),
y: grp.DoubleValue, name: moment(grp.Time).format(this.config.get('momentFullDateTimeFormat')) });
to:
chart.series[0].data.push({ x: moment(grp.Time).utc(true).format('x'),
y: grp.DoubleValue, name: moment(grp.Time).format(this.config.get('momentFullDateTimeFormat')) });
So basically I added the ".utc(true)" to the moment definition for the x value.

highcharts 3, line on column chart

http://jsfiddle.net/ramon_ackermann/PhjX7/2/
$(function () {
$('#container').highcharts({
chart: {
type:'column'
},
xAxis: {
min:0,
max:0,
categories: ["test"]
},
series: [{
"name": "ABELO",
"data": [
0.73
]
},{
"name": "UAAU",
"data": [
0.77
]
},{
"name": "ANCB",
"data": [
1.72
]
},
{
"name": "avg",
"type": "line",
"color": "#ff0000",
"data": [
{
"x": -0.5,
"y": 1.5
},{
"y": 1.5,
"dataLabels": {
"enabled": true,
"align": "right",
"verticalAlign": "bottom",
"formatter": function(){
return 'avg: ' + this.y;
},
"style": {
"fontWeight": "normal"
},
"x": 0.5
}
}
]
}
]
});
});
Before updgrading to Highcharts 3, the code above would work properly, drawing the line from left to right, but since I'm trying to upgrade to v3, I can't get the line to draw all the way to the right.
I devised the above solution from my previous question / answers (highcharts line not fully plotted)
The above sample is a simplified version of what I need, unfortunately plotLines is not a solution for me.
Simple solution is to extend another point onto your avg line:
...,{"x": 1.5, "y": 1.5}]
Why is a plotLine not appropriate?
I advice to use plotLine or use renderer.
http://api.highcharts.com/highcharts#yAxis.plotLines
http://api.highcharts.com/highcharts#Renderer.path

Resources