score:5
you are trying to use features of two highcharts type of charts - solidgauge and gauge.
it is possible to place both of them in one chart and set same (or almost the same) values for both series.
example: http://jsfiddle.net/2l1bmhb5/
$(function () {
$('#container').highcharts({
chart: {
plotbackgroundcolor: null,
plotbackgroundimage: null,
plotborderwidth: 0,
plotshadow: false
},
title: {
text: null
},
tooltip: {
enabled: false
},
pane: {
startangle: -90,
endangle: 90,
background: {
backgroundcolor: '#ccc',
borderwidth: 0,
shape: 'arc',
innerradius: '60%',
outerradius: '95%'
}
},
yaxis: {
stops: [
[1, '#f00'] // red
],
min: 0,
max: 95,
minorticklength: 0,
linewidth: 0,
tickpixelinterval: 30,
tickwidth: 2,
tickposition: 'inside',
ticklength: 5,
tickcolor: '#666',
tickpositions: [0, 72, 82.68, 95],
labels: {
distance: 10
}
},
series: [{
type: 'gauge',
data: [14],
pivot: {
radius: 0
},
datalabels: {
y: -5,
borderwidth: 0,
style: {
fontsize: '20px'
}
},
dial: {
radius: '85%',
backgroundcolor: 'red',
borderwidth: 0,
basewidth: 3,
topwidth: 3,
baselength: '100%', // of radius
rearlength: '0%'
}
}, {
type: 'solidgauge',
fillcolor: 'red',
data: [14.5],
radius: '95%'
}]
},
// add some life
function (chart) {
if (!chart.renderer.forexport) {
setinterval(function () {
var point = chart.series[0].points[0],
point2 = chart.series[1].points[0],
newval,
inc = math.round((math.random() - 0.5) * 20);
newval = point.y + inc;
if (newval < 0 || newval > 95) {
newval = point.y - inc;
}
point.update(newval, false);
point2.update(newval + 0.5);
}, 3000);
}
});
});
update:
- colors can change fluently if you set yaxis stops. api: http://api.highcharts.com/highcharts#yaxis.stops
scale of stops if 0-1, so if you want colors to be based on axis values - scale them.
stops: [
[0, '#ff0000'], // red
[76.38/95, '#00ff00'], // green
[93/95, '#0000ff'] // blue
],
other way would be to use yaxis mincolor and maxcolor to change colors. in that case axis must updated and series must be additionally binded with axes.
http://jsfiddle.net/2l1bmhb5/2/
...
if (newval < 76.38) {
color = col[0];
} else if (newval < 93) {
color = col[1];
} else {
color = col[2];
}
chart.yaxis[0].update({
stops: [
[1, color]
]
},false);
point.update(newval, false);
point2.update(newval, false);
chart.series[1].bindaxes(); //solidgauge series
chart.redraw(true);
- needle (aka dial) and pivot can be styled using options described in api.
http://api.highcharts.com/highcharts#series.pivot
http://api.highcharts.com/highcharts#series.dial
pivot: {
backgroundcolor: "#fff",
bordercolor: "#666",
borderwidth: 5,
radius: 6
},
dial: {
radius: '100%',
backgroundcolor: '#666',
borderwidth: 0,
basewidth: 5,
topwidth: 5,
baselength: '100%', // of radius
rearlength: '0%'
}
http://jsfiddle.net/2l1bmhb5/3/
lines of additional points are y axis tick lines. it is not possible using default options to change visibility of selected lines or their dash style. one way would be to change their style on load and after each redraw.
function styleticklines() { var paths = $('.highcharts-axis > path').splice(0), len = paths.length; // hide first and last paths[0].setattribute('opacity', 0); paths[len - 1].setattribute('opacity', 0); // style the rest for (var i = 1; i < len - 1; i++) { paths[i].setattribute('stroke-dasharray', '3,3'); } }
http://jsfiddle.net/2l1bmhb5/4/
other way would be to write highcharts wrapper that would change default behavior and enable setting style per selected ticks.
- at that point you might notice that tick lines are covered by series plot. if you want to avoid it, then set zindex for yaxis to e.g. 7
finall example: http://jsfiddle.net/2l1bmhb5/6/
$(function () {
var col = ['#ff0000', '#00ff00', '#0000ff'],
color;
function styleticklines() {
var paths = $('.highcharts-axis > path').splice(0),
len = paths.length;
// hide first and last
paths[0].setattribute('opacity', 0);
paths[len - 1].setattribute('opacity', 0);
// style the rest
for (var i = 1; i < len - 1; i++) {
paths[i].setattribute('stroke-dasharray', '3,3');
}
}
$('#container').highcharts({
chart: {
plotbackgroundcolor: null,
plotbackgroundimage: null,
plotborderwidth: 0,
plotshadow: false,
events: {
load: styleticklines,
redraw: styleticklines
}
},
title: {
text: null
},
tooltip: {
enabled: false
},
pane: {
startangle: -90,
endangle: 90,
background: {
backgroundcolor: '#ccc',
borderwidth: 0,
shape: 'arc',
innerradius: '60%',
outerradius: '100%'
}
},
yaxis: {
zindex: 7,
stops: [
[1, '#ff0000']
],
min: 0,
max: 95,
minorticklength: 0,
linewidth: 0,
tickpixelinterval: 30,
tickwidth: 2,
tickposition: 'inside',
ticklength: 46,
tickcolor: '#666',
tickpositions: [0, 76.38, 93, 95],
labels: {
distance: 20
}
},
series: [{
type: 'solidgauge',
fillcolor: 'red',
data: [72],
radius: '100%',
datalabels: {
y: 10,
borderwidth: 0,
style: {
fontsize: '20px'
}
}
}, {
type: 'gauge',
data: [72],
pivot: {
backgroundcolor: "#fff",
bordercolor: "#666",
borderwidth: 5,
radius: 6
},
datalabels: {
enabled: false
},
dial: {
radius: '105%',
backgroundcolor: '#666',
borderwidth: 0,
basewidth: 5,
topwidth: 5,
baselength: '100%', // of radius
rearlength: '0%'
}
}]
},
// add some life
function (chart) {
if (!chart.renderer.forexport) {
setinterval(function () {
var point = chart.series[0].points[0],
point2 = chart.series[1].points[0],
newval,
inc = math.round((math.random()) * 10);
newval = point.y + inc;
if (newval < 0 || newval > 95) {
newval = point.y - inc;
}
if (newval < 76.38) {
color = col[0];
} else if (newval < 93) {
color = col[1];
} else {
color = col[2];
}
chart.yaxis[0].update({
stops: [
[1, color]
]
}, false);
point.update(newval, false);
point2.update(newval, false);
chart.series[0].bindaxes();
chart.redraw(true);
}, 3000);
}
});
});
Source: stackoverflow.com
Related Query
- Show more data on Gauge chart with Highcharts
- Highcharts cloud issue with data source when duplicating chart
- Reload chart data via JSON with Highcharts
- Add dynamic data to line chart from mysql database with highcharts
- Highcharts - Global configuration with common code and unique data & Headings
- Highcharts - Gauge chart data label not positioning correctly
- Highcharts Solid Gauge only want to show 1 data label
- Highcharts Gauge Chart with text labels
- Highcharts show the same yAxis start and end value with multiple data series
- Splitted bar chart for paired data with highcharts
- How to Build a Column Chart in Highcharts with Data Entered Dynamically Within a CMS
- highcharts Gauge live data with ajax
- Combining Highcharts Gauge with Area Chart
- Add different symbols to highcharts chart with dynamic data
- Highcharts area chart hide graphs with one data point
- HIghcharts column graph with more than 50 data points
- Highcharts gantt chart : Task progress indicator need to show a single task for various status like completed,inprogress etc with different colors
- Highcharts line chart all points disappear when have more than one points with same X Axis
- Highcharts - draw line chart with summed values but show breakup on hover
- Returning JSON file with cURL to use data in a HighCharts stock chart
- Highcharts GANTT chart - need to allow category with no data
- Rendering more than one chart with Highcharts using Angular js Directives
- highcharts Scatter Chart not loading with LOTS of data
- Pass data to click event callback in Highstock chart with more then 1000 entries
- How to create a solid gauge chart with Highcharts in angular 6?
- Highcharts display label for pie chart using html table as data source
- HighCharts populate Pie Chart with data from SQL Database
- Highcharts series doesnt show data and render the chart
- Extract data series from a JSON array for a Highcharts chart with 2 y-axis
- HighCharts column chart populated with series data from a function
More Query from same tag
- Create graphs similar to Pew Research site
- Highchart can't be displayed
- Highcharts breaks on axis
- Bubble chart with Highstock, how to create different tooltips?
- Displaying data ArrayList (EJB + Servlet + JSP(JSTL)) to JavaScript ArrayList
- Highchart maps / Highmaps update vue data properties on clicking country
- Android highchart how to disable export button?
- Setting custom value as label in bar highchart (Rshiny)
- Is there a chart ID in Highcharts
- Highstocks compare stocks how to define data?
- Highcharts assign label to to x-axis max value
- Adjust space to the sides of highchart series
- Specific graph in highcharts
- How do I add a custom FirstLabel in HighCharts?
- How to modify highcharts legend item click event?
- Highcharts - Xaxis should show only days and month, hide milliseconds
- Want to move y-axis scrollbar with mouse wheel in highcharts/highstock
- Highcharts - Organizing the raw data
- HighCharts remove $ and % symbols from custom html table when creating graph
- Get point by ID from highchart with multiple series
- I am facing image cut issue after upgrade Highchart version from 6.0.7 to 8.0.4
- highcharts-vue xAxis.tickPositioner with series.data.length == 0
- Draw multiple series in Highchart from single JSON data container
- How to set min start date for Highcharts plot?
- passing data from database to highcharts in Django
- How to position labels for plotbands on y axis in Highcharts
- Get SVG Data from Highcharts without displaying the chart
- Highcharts steps to setup own server for download
- How to have first level as column chart and second level as Fixed placement columns in drill down highcharts
- highcharter hcaes "group" usage while plotting large amounts of data with highchart2()