Built linear gauge with highcharts (with pointer) - highcharts

I'm trying to recreate a linear gauge chart of fusionchart in highcharts. This is the example that I am trying to recreate.
Head:
<script type="text/javascript" src="https://static.fusioncharts.com/code/latest/fusioncharts.js"></script>
<script type="text/javascript" src="https://static.fusioncharts.com/code/latest/fusioncharts.charts.js"></script>
<script type="text/javascript" src="https://static.fusioncharts.com/code/latest/fusioncharts.widgets.js"></script>
<script type="text/javascript" src="https://static.fusioncharts.com/code/latest/themes/fusioncharts.theme.fint.js"></script>
<div id="chart-container">FusionCharts will render here</div>
Body:
FusionCharts.ready(function () {
var cpuGauge = new FusionCharts({
type: 'hlineargauge',
renderAt: 'chart-container',
id: 'cpu-linear-gauge',
width: '400',
height: '190',
dataFormat: 'json',
dataSource: {
"chart": {
"theme": "fint",
"lowerLimit": "-1.9",
"upperLimit": "4.4",
"numberSuffix": "%",
"chartBottomMargin": "40",
"valueFontSize": "11",
"pointerBgColor": "#000000",
"baseFontColor": "#000000",
"decimalSeparator": ",",
"forceDecimals": "1",
"decimals": "1",
"valueFontBold": "0"
},
"colorRange": {
"color": [
{
"minValue": "-1.9",
"maxValue": "-0.1",
"label": "",
"code": "#e51b1b",
},
{
"minValue": "-0.1",
"maxValue": "1.0",
"label": "",
"code": "#fa7921",
},
{
"minValue": "1.0",
"maxValue": "1.5",
"label": "",
"code": "#fde74c",
},
{
"minValue": "1.5",
"maxValue": "4.4",
"label": "",
"code": "#9bc53d",
}
]
},
"pointers": {
"pointer": [
{
"value": "2"
}
]
},
}
})
.render();
});
The highcharts chart must take over the following properties:
Negative values
At least 4 groups (colors)
Pointer (indication marker) with number at top
In addition, I would really appreciate if there is an animation where you can see the pointer moving.
The bullet graph from highcharts comes closest to the fusionchart. I have made a first step (example) with this graph
Head:
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/bullet.js"></script>
<div id="container1"></div>
Body:
Highcharts.setOptions({
chart: {
inverted: true,
marginLeft: 135,
type: 'bullet'
},
title: {
text: null
},
legend: {
enabled: false
},
yAxis: {
gridLineWidth: 0
},
plotOptions: {
series: {
pointPadding: 0.25,
borderWidth: 0,
color: '#000',
targetOptions: {
width: '200%'
}
}
},
credits: {
enabled: false
},
exporting: {
enabled: false
}
});
Highcharts.chart('container1', {
chart: {
marginTop: 40
},
title: {
text: ''
},
xAxis: {
categories: "P"
},
yAxis: {
plotBands: [{
from: -1.9,
to: -0.1,
color: '#e51b1b'
}, {
from: -0.1,
to: 1,
color: '#fa7921'
}, {
from: 1,
to: 1.5,
color: '#fde74c'
}, {
from: 1.5,
to: 4.4,
color: '#9bc53d'
}],
labels: {
format: '{value}%'
},
title: null
},
series: [{
data: [{
y: 0,
target: 2
}]
}],
tooltip: {
pointFormat: '<b>{point.y}</b> (with target at {point.target})'
}
});
CSS:
#container1 {
max-width: 800px;
height: 115px;
margin: 1em auto;
}
But encounter a number of problems:
Negative numbers are not working
Pointer
Maximum is not shown (stops before 4.4)

With reference to this post. I have modified this chart with yAxis.tickPositioner and min, max property of yAxis
$(function () {
/**
* Highcharts Linear-Gauge series plugin
*/
(function (H) {
var defaultPlotOptions = H.getOptions().plotOptions,
columnType = H.seriesTypes.column,
wrap = H.wrap,
each = H.each;
defaultPlotOptions.lineargauge = H.merge(defaultPlotOptions.column, {});
H.seriesTypes.lineargauge = H.extendClass(columnType, {
type: 'lineargauge',
//inverted: true,
setVisible: function () {
columnType.prototype.setVisible.apply(this, arguments);
if (this.markLine) {
this.markLine[this.visible ? 'show' : 'hide']();
}
},
drawPoints: function () {
// Draw the Column like always
columnType.prototype.drawPoints.apply(this, arguments);
// Add a Marker
var series = this,
chart = this.chart,
inverted = chart.inverted,
xAxis = this.xAxis,
yAxis = this.yAxis,
point = this.points[0], // we know there is only 1 point
markLine = this.markLine,
ani = markLine ? 'animate' : 'attr';
// Hide column
point.graphic.hide();
if (!markLine) {
var path = inverted ? ['M', 0, 0, 'L', -5, -5, 'L', 5, -5, 'L', 0, 0, 'L', 0, 0 + xAxis.len] : ['M', 0, 0, 'L', -5, -5, 'L', -5, 5,'L', 0, 0, 'L', xAxis.len, 0];
markLine = this.markLine = chart.renderer.path(path)
.attr({
fill: series.color,
stroke: series.color,
'stroke-width': 1
}).add();
}
markLine[ani]({
translateX: inverted ? xAxis.left + yAxis.translate(point.y) : xAxis.left,
translateY: inverted ? xAxis.top : yAxis.top + yAxis.len - yAxis.translate(point.y)
});
}
});
})(Highcharts);
$('#container').highcharts({
chart: {
type: 'lineargauge',
inverted: true
},
title: {
text: 'A Horizontal Linear Gauge'
},
xAxis: {
lineColor: '#C0C0C0',
labels: {
enabled: false
},
tickLength: 0,
},
yAxis: {
min: -1.9,
max: 4.4,
tickPositions: [-1.9, -0.1,1,1.5 ,4.4],
tickLength: 1,
tickWidth: 1,
tickColor: '#C0C0C0',
gridLineColor: '#C0C0C0',
gridLineWidth: 1,
minorTickInterval: 5,
minorTickWidth: 1,
minorTickLength: 5,
minorGridLineWidth: 0,
startOnTick: true,
endOnTick: true,
title: null,
labels: {
format: '{value}%'
},
plotBands: [{
from:-1.9,
to: -0.1,
color: 'rgba(229, 27, 27, 1)'
}, {
from: -0.1,
to: 1.0,
color: 'rgba(250, 121, 33, 1)'
}, {
from: 1.0,
to: 1.5,
color: 'rgba(253, 231, 76, 1)'
},
{
from: 1.5,
to: 4.4,
color: 'rgba(155, 197, 61, 1)'
}]
},
legend: {
enabled: false
},
series: [{
data: [1.1],
color: '#000000',
dataLabels: {
enabled: true,
align: 'center',
format: '{point.y}%',
y: 10,
}
}]
}, // Add some life
function (chart) {
setInterval(function () {
Highcharts.each(chart.series, function (serie) {
var point = serie.points[0],
newVal,
inc = (Math.random() - 0.5) *10;
newVal = point.y + inc;
if (newVal < -1.9 || newVal > 4.4) {
newVal = point.y - inc;
}
point.update(Math.floor(newVal));
});
}, 2000);
});
});
Fiddle demo

Related

Spline line is very curved, how to smooth it?

A smoother line is needed (the line should rise smoothly and evenly), but the values ​​should not change. Is it possible to build a more straight line without changing the values?
Screen with explanations: http://prntscr.com/qudf96
And my code:
<script>
function reDrawCalc(gdata, gcurr, nums = 2) {
Highcharts.chart('container', {
chart: {
height: 400,
type: 'area',
margin: [20, 0, 20, 0]
},
title: {
text: null
},
subtitle: {
text: null
},
exporting: {
enabled: false
},
xAxis: {
gridLineWidth: 1,
categories: ['One', 'Two', 'Three', 'Four', 'Five']
},
yAxis: {
gridLineWidth: 0,
},
tooltip: {
enabled: false,
crosshairs: true
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
useHTML: true,
inside: false,
style: {
fontFamily: 'Rubik, sans-serif',
textTransform: 'uppercase',
fontSize: 'none',
fontWeight: 'normal',
textShadow: 'none'
},
formatter: function() {
return '<div class="chitem-time">'+ this.x+'</div>'
+'<div class="chitem-val">'+ Highcharts.numberFormat(this.y,nums)+'<sup>'+gcurr+'</sup></div>';
}
}
}
},
series: [{
type: 'areaspline',
data: gdata,
lineWidth: 5,
color: '#f0c997',
fillColor:'transparent'
}],
responsive: {
rules: [{
condition: {
maxWidth: 500
},
chartOptions: {
chart: {
height: 350,
type: 'area',
margin: [20, 0, 20, 0]
},
series: [{
type: 'areaspline',
data: gdata,
lineWidth: 3,
color: '#f0c997',
fillColor:'transparent'
}],
}
}]
}
});
}
</script>
Is it possible to do it? And how to modify my code for it?
Thank you very much in advance!
As I mentioned in the comment current line shape is at it is because of the points positions on the chart. If you don't need to keep points actual positions the solution which you can use is to use the dummy data for the points and use the correct one in the dataLabels. See:
Demo: https://jsfiddle.net/BlackLabel/fshx3n50/
data: [{
y: 5,
z: 0.20
}, {
y: 10,
z: 1.40
}, {
y: 18,
z: 6.20
}, {
y: 30,
z: 18.00
}, {
y: 50,
z: 73.00
}],
I also changed the formatter function to display the z value in dataLabel:
formatter: function() {
return '<div class="chitem-time">' + this.x + '</div>' +
'<div class="chitem-val">' + Highcharts.numberFormat(this.point.z) + '<sup>REM</sup></div>';
}

Set yAxis background color in Highstock

I am trying to color Y axes on a Highstock chart, I tried changing the plotBackgroundColor but it changes the whole plot area.
2 images are more than 2 thousand words:
On the left I have my current result, it changes the whole plot area background color, so is not easy to see where a chart ends and the next one starts, On the right is the expected result, each axis is separated by the background color and a gray border.
This is my code:
var p0 = [
[1540166400000,122.85],
[1540170000000,122.33],
[1540173600000,120.96],
[1540177200000,120.77],
[1540180800000,120.84],
[1540184400000,120.61],
[1540188000000,120.83],
[1540191600000,121.04],
[1540195200000,120.67],
[1540198800000,121.05],
[1540202400000,122.29],
[1540206000000,122.45],
[1540209600000,123.13],
[1540213200000,123.74],
[1540216800000,124.07],
[1540224000000,123.28],
[1540227600000,122.59],
[1540231200000,122.98],
[1540234800000,123.51],
[1540238400000,123.38],
[1540242000000,123.45],
[1540245600000,123.15],
[1540249200000,123.72],
[1540252800000,123.65],
[1540256400000,123.65],
[1540260000000,123.28],
[1540263600000,122.56],
[1540267200000,122.41],
[1540270800000,122.23],
[1540274400000,122.22],
[1540278000000,122.4],
[1540281600000,121.57],
[1540285200000,121.69],
[1540288800000,121.98]];
var p1 = [
[1540166400000,127.27],
[1540170000000,126.74],
[1540173600000,125.46],
[1540177200000,125.49],
[1540180800000,125.71],
[1540184400000,125.49],
[1540188000000,125.57],
[1540191600000,126.02],
[1540195200000,125.62],
[1540198800000,125.88],
[1540202400000,126.49],
[1540206000000,127.11],
[1540209600000,127.97],
[1540213200000,128.84],
[1540216800000,128.66],
[1540224000000,127.63],
[1540227600000,126.98],
[1540231200000,127.63],
[1540234800000,127.77],
[1540238400000,127.21],
[1540242000000,127.24],
[1540245600000,126.87],
[1540249200000,126.99],
[1540252800000,127.04],
[1540256400000,127.47],
[1540260000000,126.91],
[1540263600000,126.3],
[1540267200000,126.36],
[1540270800000,126.07],
[1540274400000,126.09],
[1540278000000,126.18],
[1540281600000,125.54],
[1540285200000,125.7],
[1540288800000,126.06]];
chart = new Highcharts.StockChart({
chart: {
renderTo: "container",
backgroundColor:'#EBEBEB',
plotBackgroundColor:'#FFFFFF',
plotBorderColor: '#999999',
plotBorderWidth: 2
},
title: {
text: "Coloring axis",
},
legend: {
enabled: false
},
xAxis: {
ordinal: false
},
yAxis: [
{
minorTicks: 1,
height: "46%",
top: "4%"
},
{
minorTicks: 1,
height: "46%",
top: "54%"
}
],
series: [
{
name: "Val1 1",
data: p0,
yAxis: 0,
},
{
name: "Presión 2",
data: p1,
yAxis: 1,
},
]
});
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<div id="container" style="width: 600px; height: 600px;"></div>
A workaround to achieve what you are after can be done by using a third yAxis, like this:
{
height: "4%",
top: "50%",
labels: {
enabled: false
},
min: 0,
max: 1,
minorGridLineWidth: 0,
gridLineWidth: 0,
plotBands: [{
color: '#EBEBEB',
borderColor:'#999999',
borderWidth: 2,
from: 0.05,
to: 0.95,
}
}
var p0 = [
[1540166400000,122.85],
[1540170000000,122.33],
[1540173600000,120.96],
[1540177200000,120.77],
[1540180800000,120.84],
[1540184400000,120.61],
[1540188000000,120.83],
[1540191600000,121.04],
[1540195200000,120.67],
[1540198800000,121.05],
[1540202400000,122.29],
[1540206000000,122.45],
[1540209600000,123.13],
[1540213200000,123.74],
[1540216800000,124.07],
[1540224000000,123.28],
[1540227600000,122.59],
[1540231200000,122.98],
[1540234800000,123.51],
[1540238400000,123.38],
[1540242000000,123.45],
[1540245600000,123.15],
[1540249200000,123.72],
[1540252800000,123.65],
[1540256400000,123.65],
[1540260000000,123.28],
[1540263600000,122.56],
[1540267200000,122.41],
[1540270800000,122.23],
[1540274400000,122.22],
[1540278000000,122.4],
[1540281600000,121.57],
[1540285200000,121.69],
[1540288800000,121.98]];
var p1 = [
[1540166400000,127.27],
[1540170000000,126.74],
[1540173600000,125.46],
[1540177200000,125.49],
[1540180800000,125.71],
[1540184400000,125.49],
[1540188000000,125.57],
[1540191600000,126.02],
[1540195200000,125.62],
[1540198800000,125.88],
[1540202400000,126.49],
[1540206000000,127.11],
[1540209600000,127.97],
[1540213200000,128.84],
[1540216800000,128.66],
[1540224000000,127.63],
[1540227600000,126.98],
[1540231200000,127.63],
[1540234800000,127.77],
[1540238400000,127.21],
[1540242000000,127.24],
[1540245600000,126.87],
[1540249200000,126.99],
[1540252800000,127.04],
[1540256400000,127.47],
[1540260000000,126.91],
[1540263600000,126.3],
[1540267200000,126.36],
[1540270800000,126.07],
[1540274400000,126.09],
[1540278000000,126.18],
[1540281600000,125.54],
[1540285200000,125.7],
[1540288800000,126.06]];
chart = new Highcharts.StockChart({
chart: {
renderTo: "container",
backgroundColor:'#EBEBEB',
plotBackgroundColor:'#FFFFFF',
plotBorderColor: '#999999',
plotBorderWidth: 2
},
title: {
text: "Coloring axis",
},
legend: {
enabled: false
},
xAxis: {
ordinal: false
},
yAxis: [
{
minorTicks: 1,
height: "46%",
top: "4%",
plotLines: [
]
},
{
minorTicks: 1,
height: "46%",
top: "54%",
plotLines: [
]
},
{
height: "4%",
top: "50%",
labels: {
enabled: false
},
min: 0,
max: 1,
minorGridLineWidth: 0,
gridLineWidth: 0,
plotBands: [{
color: '#EBEBEB',
borderColor:'#999999',
borderWidth: 2,
from: 0.05,
to: 0.95,
}]
}
],
series: [
{
name: "Val1 1",
data: p0,
yAxis: 0,
},
{
name: "Presión 2",
data: p1,
yAxis: 1,
},
]
});
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<div id="container" style="width: 600px; height: 600px;"></div>
JSFiddle example: https://jsfiddle.net/ewolden/q826ze9v/8/
The "correct" way to achieve what you are after would be to follow highcharts' syncronized chart example: https://www.highcharts.com/demo/synchronized-charts. This is more complicated, but allows you much more customization, and would probably prove easier to work with long term.
I finally did it using highcharts SVGRenderer, drawing white rectangles for each axis at z-index:-1 to draw it on the background.
I hope this helps someone!
var p0 = [
[1540166400000,122.85],
[1540170000000,122.33],
[1540173600000,120.96],
[1540177200000,120.77],
[1540180800000,120.84],
[1540184400000,120.61],
[1540188000000,120.83],
[1540191600000,121.04],
[1540195200000,120.67],
[1540198800000,121.05],
[1540202400000,122.29],
[1540206000000,122.45],
[1540209600000,123.13],
[1540213200000,123.74],
[1540216800000,124.07],
[1540224000000,123.28],
[1540227600000,122.59],
[1540231200000,122.98],
[1540234800000,123.51],
[1540238400000,123.38],
[1540242000000,123.45],
[1540245600000,123.15],
[1540249200000,123.72],
[1540252800000,123.65],
[1540256400000,123.65],
[1540260000000,123.28],
[1540263600000,122.56],
[1540267200000,122.41],
[1540270800000,122.23],
[1540274400000,122.22],
[1540278000000,122.4],
[1540281600000,121.57],
[1540285200000,121.69],
[1540288800000,121.98]];
var p1 = [
[1540166400000,127.27],
[1540170000000,126.74],
[1540173600000,125.46],
[1540177200000,125.49],
[1540180800000,125.71],
[1540184400000,125.49],
[1540188000000,125.57],
[1540191600000,126.02],
[1540195200000,125.62],
[1540198800000,125.88],
[1540202400000,126.49],
[1540206000000,127.11],
[1540209600000,127.97],
[1540213200000,128.84],
[1540216800000,128.66],
[1540224000000,127.63],
[1540227600000,126.98],
[1540231200000,127.63],
[1540234800000,127.77],
[1540238400000,127.21],
[1540242000000,127.24],
[1540245600000,126.87],
[1540249200000,126.99],
[1540252800000,127.04],
[1540256400000,127.47],
[1540260000000,126.91],
[1540263600000,126.3],
[1540267200000,126.36],
[1540270800000,126.07],
[1540274400000,126.09],
[1540278000000,126.18],
[1540281600000,125.54],
[1540285200000,125.7],
[1540288800000,126.06]];
chart = new Highcharts.StockChart({
chart: {
renderTo: "container",
backgroundColor:'#EBEBEB'
},
title: {
text: "Coloring axis",
},
legend: {
enabled: false
},
xAxis: {
ordinal: false
},
yAxis: [
{
minorTicks: 1,
height: "46%",
top: "4%"
},
{
minorTicks: 1,
height: "46%",
top: "54%"
}
],
series: [
{
name: "Val1 1",
data: p0,
yAxis: 0,
},
{
name: "Presión 2",
data: p1,
yAxis: 1,
},
]
}, function (chart) { // on complete
var yaxisColl = chart.yAxis;
for(f=0;f<yaxisColl.length;f++){
axis = yaxisColl[f];
chart.renderer.rect(10, axis.top, axis.width, axis.height, 0, 2)
.attr({
'stroke-width': 2,
stroke: '#999999',
fill: '#FFFFFF',
zIndex: -1
})
.add();
}
});
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<div id="container" style="width: 600px; height: 600px;"></div>
You could also do it using plotBands on each yAxis:
yAxis: [
{
minorTicks: 1,
height: "46%",
top: "4%",
plotBands: [{
from:-1000,
to:1000,
color:'rgb(255,255,255)'
}]
},
{
minorTicks: 1,
height: "46%",
top: "54%",
plotBands: [{
from:-1000,
to:1000,
color:'rgb(255,255,255)'
}]
}
]
Example: http://jsfiddle.net/jlbriggs/k2syL51r/

highcharts Unable to create plotbands

Im trying to create plotbands but does not work correctly.
Here is my fiddle and code.
https://jsfiddle.net/z0h85fku/
Javascript
$(function() {
categories = ["09/07/2016 00:00", "09/07/2016 00:01", "09/07/2016 00:02", "09/07/2016 00:03", "09/07/2016 00:04"]
rate_1 = [0.8, 0.54, 0.6, 0.3, 0.4]
rate_2 = [0.33, 0.16, 0.33, 0.3, 0.38]
rate_3 = [0.03, 0.04, 0.05, 0.03, 0.01]
var addCallout = function(chart) {
$('.callout').remove();
var xAxis = chart.xAxis[0],
yAxis = chart.yAxis[0],
series = chart.series[0],
point = series.data[0];
console.log('xAxis == ', xAxis)
console.log('yAxis == ', yAxis.toPixels)
console.log('series == ', series)
console.log('point == ', point)
console.log(point.plotY)
console.log(point.plotX)
var a = chart.renderer.label('<div class="callout top">This is the callout text!</div>', point.plotX + chart.plotLeft - 20,
point.plotY + chart.plotTop - 70, 'callout', null, null, true).add();
};
$('#container').highcharts({
chart: {
// type: 'bar',
events: {
load: function() {
addCallout(this);
},
redraw: function() {
addCallout(this);
},
}
},
title: {
text: 'Spikes Graph',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
events: {
load: function() {
// addCallout(this);
},
redraw: function() {
addCallout(this);
},
},
series: [{
turboThreshold: 2000 // to accept point object configuration
}],
xAxis: {
categories: categories,
<!-- tickInterval: 60,-->
plotBands: [{
color: 'orange', // Color value
// from: Date.UTC(09/07/2016 02:00), // Start of the plot band
// Date.UTC(year,month,day,hours,minutes,seconds,millisec)
from: Date.UTC(2016,9,7,0,0),
to: Date.UTC(2016,9,7,4,0)
// to: '09/07/2016 05:00' // End of the plot band
}],
type:'datetime'
},
yAxis: {
title: {
text: 'Error Rate'
},
min: 0,
max: 5,
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}],
labels: {
format: '{value} %'
}
},
tooltip: {
valueSuffix: '°C'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [
// {turboThreshold: 2000 },
{
name: 'Rate-1',
data: rate_1,
turboThreshold: 2000,
lineWidth: 1,
dataLabels: {
enabled: true,
useHTML: true,
style: {
fontWeight: 'bold'
},
},
}, {
name: 'Rate-2',
data: rate_2,
turboThreshold: 2000,
lineWidth: 1
}, {
name: 'Rate-3',
data: rate_3,
turboThreshold: 2000,
lineWidth: 1
}
]
});
});

Drawing horizontal lines parallel to x axis using highcharts.js

Below is the fiddle for a Pareto chart. I want to draw a horizontal line parallel to the x-axis which spans from left to right and ends at the 80% mark on the y-axis. I want to do this always while plotting a Pareto chart.
Can you let me know if there's a way to do this dynamically?
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'column',
borderWidth:1,
borderColor:'#ccc',
marginLeft:110,
marginRight:50,
//backgroundColor:'#eee',
//plotBackgroundColor:'#fff',
},
title:{
text:'Pareto Test 1'
},
legend:{
},
tooltip:{
formatter:function(){
if(this.series.name == 'Line'){
var pcnt = Highcharts.numberFormat((this.y / 415 * 100),0,'.');
return pcnt + '%';
}
return this.y;
}
},
plotOptions: {
series: {
shadow:false,
}
},
xAxis:{
categories:['A','B','C','D','E','F','G','H'],
lineColor:'#999',
lineWidth:1,
tickColor:'#666',
tickLength:3,
title:{
text:'X Axis Title',
style:{
color:'#000'
}
}
},
yAxis:[{
min:0,
//endOnTick:false,
//lineColor:'#999',
lineWidth:1,
//tickColor:'#666',
//tickWidth:1,
//tickLength:3,
//gridLineColor:'#ddd',
/* title:{
text:'Y Axis Title',
rotation:0,
margin:50,
style:{
color:'#000'
}
}*/
},{
title:{text:''},
//alignTicks:false,
gridLineWidth:0,
lineColor:'#999',
lineWidth:1,
tickColor:'#666',
tickWidth:1,
tickLength:3,
tickInterval:415 / 20,
endOnTick:false,
opposite:true,
linkedTo:0,
labels:{
formatter:function(){
var pcnt = Highcharts.numberFormat((this.value / 415 * 100),0,'.');
return pcnt + '%';
}
}
}],
series: [{
//yAxis:0,
data: [115,75,60,55,45,30,20,15],
},{
type:'line',
name:'Line',
//yAxis:0,
data: [115,190,250,305,350,380,400,415],
}]
});
<script type="text/javascript" src="http://code.highcharts.com/highcharts.src.js"></script>
<div id="container" style="height: 400px"></div>
You can set this up the same way you calculated what 80% is. See the Fiddle below. Here is some sample code to add plotLines:
plotLines: [{
color: '#FF0000',
width: 2,
value: .80 * 415 // Need to set this probably as a var.
}]
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'column',
borderWidth: 1,
borderColor: '#ccc',
marginLeft: 110,
marginRight: 50,
//backgroundColor:'#eee',
//plotBackgroundColor:'#fff',
},
title: {
text: 'Pareto Test 1'
},
legend: {
},
tooltip: {
formatter: function() {
if (this.series.name == 'Line') {
var pcnt = Highcharts.numberFormat((this.y / 415 * 100), 0, '.');
return pcnt + '%';
}
return this.y;
}
},
plotOptions: {
series: {
shadow: false,
}
},
xAxis: {
categories: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'],
lineColor: '#999',
lineWidth: 1,
tickColor: '#666',
tickLength: 3,
title: {
text: 'X Axis Title',
style: {
color: '#000'
}
}
},
yAxis: [{
min: 0,
//endOnTick:false,
//lineColor:'#999',
lineWidth: 1
//tickColor:'#666',
//tickWidth:1,
//tickLength:3,
//gridLineColor:'#ddd',
/* title:{
text:'Y Axis Title',
rotation:0,
margin:50,
style:{
color:'#000'
}
}*/
}, {
title: {
text: ''
},
//alignTicks:false,
gridLineWidth: 0,
lineColor: '#999',
lineWidth: 1,
tickColor: '#666',
tickWidth: 1,
tickLength: 3,
tickInterval: 415 / 20,
endOnTick: false,
opposite: true,
linkedTo: 0,
labels: {
formatter: function() {
var pcnt = Highcharts.numberFormat((this.value / 415 * 100), 0, '.');
return pcnt + '%';
}
},
plotLines: [{
color: '#FF0000',
width: 2,
value: .80 * 415 // Need to set this probably as a var.
}]
}],
series: [{
//yAxis:0,
data: [115, 75, 60, 55, 45, 30, 20, 15]
}, {
type: 'line',
name: 'Line',
//yAxis:0,
data: [115, 190, 250, 305, 350, 380, 400, 415]
}]
});
<script type="text/javascript" src="http://code.highcharts.com/highcharts.src.js"></script>
<div id="container" style="height: 400px"></div>
What you want to look at is a plot line:
http://api.highcharts.com/highcharts#yAxis.plotLines
{{EDIT:
Also, look here for slightly improved way of getting the data sum dynamically:
Highcharts percentage of total for simple bar chart

remove grid line on chart

I have the charts of lib HighCharts and I want to remove the gridline of yAxis on charts
I write gridLineWidth: 0
but gridlines are not removing
All code:
<script type="text/javascript">
(function($){ // encapsulate jQuery
$(function() {
Highcharts.setOptions({
lang: {
rangeSelectorZoom: 'Маcштаб',
rangeSelectorFrom: 'От',
rangeSelectorTo: 'До',
thousandsSep: ' '
},
global: {
useUTC: false
}
});
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function(data) {
// Create the chart
window.chart = new Highcharts.StockChart({
chart : {
borderColor: 'white',
renderTo : <?php echo "cont".$i; ?>,
backgroundColor: '#f9f9f9' // Сделаем слегка серый фон
},
rangeSelector: {
buttons: [
{
type: 'week',
count: 1,
text: 'Неделя',
},
{
type: 'month',
count: 1,
text: 'Месяц',
},
{
type: 'year',
count: 1,
text: 'Год'
},
{
type: 'all',
text: 'Всё'
}],
inputDateFormat: '%d.%m.%Y', // Меняем на привычный для нас формат даты в интервалах
inputEditDateFormat: '%d.%m.%Y',
buttonTheme: {
width: 43 // Увеличим ширину кнопки
},
selected: 1 // Какая кнопка выбрана по умолчанию
},
yAxis: [{
gridLineWidth: 0,
plotBands: [{
color: 'rgba(1, 143, 189, 1)',
from: -2,
to: 11
},
{
color: 'rgba(157, 200, 5, 1)',
from: 11,
to: 21
},
{
color: 'rgba(202, 1, 94, 1)',
from: 21,
to: 50
}],
title: {
text: 'Позиции'
},
startOnTick: false,
// min: 1,
showFirstLabel: true,
showLastLabel: true,
reversed: true,
tickPositioner: function(min, max) {
// specify an interval for ticks or use max and min to get the interval
var interval = Math.round((max-min)/5);
// push the min value at beginning of array
var dataMin=this.dataMin;
var dataMax=this.dataMax;
var positions = [dataMin];
var defaultPositions = this.getLinearTickPositions(interval, dataMin, max);
//push all other values that fall between min and max
for (var i = 0; i < defaultPositions.length; i++) {
if (defaultPositions[i] > dataMin && defaultPositions[i] < dataMax) {
positions.push(defaultPositions[i]);
}
}
// push the max value at the end of the array
positions.push(dataMax);
return positions;
},
//changed min valuereversed: true
}],
navigator: {
enabled: false,
maskFill: 'rgba(255, 255, 255, 0.45)',
//margin: 20,
series: {
type: 'areaspline',
color: 'rgba(255, 255, 255, 0.00)',
fillOpacity: 0.4,
dataGrouping: {
smoothed: false
},
lineWidth: 2,
lineColor: '#e9cc00',
marker: {
enabled: false
},
shadow: true
},
yAxis: {
reversed: true
}
},
xAxis : {
gridLineWidth: 0,
type: 'datetime',
title : {
text : ' '
},
},
title : {
//text : 'Позиции сайта'
},
legend: {
enabled: true,
align: 'center',
itemWidth: 234, // указал ширину, чтобы выводились сайты в 4 колонки
verticalAlign: 'top'
},
series : [{
lineColor: 'white',
name : 'Позиция в яндексе',
id : 'dataseries',
data : <?php echo $d ?>,
tooltip: {
backgroundColor: 'rgba(250, 250, 250, .85)', // Фон немного темнее
borderColor: 'rgba(100, 100, 100, .90)', // Цвет границы (по умолчанию меняется автоматом)
xDateFormat: '%d.%m.%Y %H:%M', // Наш формат даты
// Тут немного увеличиваем размер даты
headerFormat: '<span style="font-size: 12px">{point.key}</span><br/>',
// Формат надписей в подсказке, названия цветом графика, а значения жирным
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b><br/>',
//valueDecimals: 2
}
}]
});
});
});
})(jQuery);
</script>
The problem is not the gridLineWidth. You've set that correctly.
In addition you need to set the minorGridLineWidth that you have to set to 0
Working demo
If you doesn't want to touch the config object, you just hide the grid by css:
.chart-container .highcharts-grid {
display: none;
}
you just need to gridLineWidth set to 0
yAxis: {
min:0,
categories: ["","Low","Medium","High"],
tickWidth: 0,
crosshair: false,
lineWidth: 0,
gridLineWidth:0,//Set this to zero
title: '',
labels: {
formatter: function () {
return this.value;labels
}
},
showEmpty: false
}
None of the mentioned solutions worked for me, so this one finally worked (taken from Sparklines examples: https://www.highcharts.com/demo/sparkline):
yAxis: {
startOnTick: false,
endOnTick: false,
tickPositions: [],
}
for all other lines here is what worked for me, in some cases using line transparency as the color was the only solution I could find.
$(function() {
$('#container').highcharts({
colors: ['#00f900', '#ffff3c', '#ff2600'],
credits: {
enabled: false
},
exporting: {
enabled: false
},
legend: {
itemDistance: 60
},
lineColor: 'red',
chart: {
type: 'column',
backgroundColor: 'transparent'
},
title: {
text: ''
},
legend: {
itemStyle: {
color: 'white',
fontWeight: 'normal',
fontFamily: 'helvetica',
fontSize: '12px'
}
}
// ....rest in js fiddle
http://jsfiddle.net/fv50sLkj/23/

Resources