highchart activity gauge chart using json data from a file - json

I am new to using highcharts.js. I want to create an activity gauge chart using data from a json file or url. I have understood how they draw the chart but failed to understand the data format used in json to display the chart.
Here is my code
var options = {
chart: {
type: 'solidgauge',
marginTop: 50
},
title: {
text: 'Activity',
style: {
fontSize: '24px'
}
},
tooltip: {
borderWidth: 0,
backgroundColor: 'none',
shadow: false,
style: {
fontSize: '16px'
},
pointFormat: '{series.name}<br><span style="font-size:2em; color: {point.color}; font-weight: bold">{point.y}%</span>',
positioner: function (labelWidth, labelHeight) {
return {
x: 200 - labelWidth / 2,
y: 180
};
}
},
pane: {
startAngle: 0,
endAngle: 360,
background: [{ // Track for Move
outerRadius: '112%',
innerRadius: '88%',
backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0.3).get(),
borderWidth: 0
}, { // Track for Exercise
outerRadius: '87%',
innerRadius: '63%',
backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[1]).setOpacity(0.3).get(),
borderWidth: 0
}, { // Track for Stand
outerRadius: '62%',
innerRadius: '38%',
backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[2]).setOpacity(0.3).get(),
borderWidth: 0
}]
},
yAxis: {
min: 0,
max: 100,
lineWidth: 0,
tickPositions: []
},
plotOptions: {
solidgauge: {
borderWidth: '34px',
dataLabels: {
enabled: false
},
linecap: 'round',
stickyTracking: false
}
},
series: []
};
var gauge1;
$.getJSON('bryan.json', function(json){
console.log(json)
options.chart.renderTo = 'container';
options.series.data = json
gauge1 = new Highcharts.Chart(options);
});
/**
* In the chart load callback, add icons on top of the circular shapes
*/
function callback()
{
// Move icon
this.renderer.path(['M', -8, 0, 'L', 8, 0, 'M', 0, -8, 'L', 8, 0, 0, 8])
.attr({
'stroke': '#ffffff',
'stroke-linecap': 'round',
'stroke-linejoin': 'round',
'stroke-width': 2,
'zIndex': 10
})
.translate(190, 26)
.add(this.series[2].group);
// Exercise icon
this.renderer.path(['M', -8, 0, 'L', 8, 0, 'M', 0, -8, 'L', 8, 0, 0, 8, 'M', 8, -8, 'L', 16, 0, 8, 8])
.attr({
'stroke': '#ffffff',
'stroke-linecap': 'round',
'stroke-linejoin': 'round',
'stroke-width': 2,
'zIndex': 10
})
.translate(190, 61)
.add(this.series[2].group);
// Stand icon
this.renderer.path(['M', 0, 8, 'L', 0, -8, 'M', -8, 0, 'L', 0, -8, 8, 0])
.attr({
'stroke': '#ffffff',
'stroke-linecap': 'round',
'stroke-linejoin': 'round',
'stroke-width': 2,
'zIndex': 10
})
.translate(190, 96)
.add(this.series[2].group);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container" style="width: 400px; height: 400px; margin: 0 auto">
</div>
And here is my json data which i thout might be rendered but it didnot.
data.json

First of all, instead of options.series.data = json, you need to create the first series and then populate its data array with your data. Also, set in each point different radius and innerRadius properties. Take a look at the example below.
API Reference:
http://api.highcharts.com/highcharts/series.solidgauge.data.radius
http://api.highcharts.com/highcharts/series.solidgauge.data.innerRadius
Example:
http://jsfiddle.net/x3cne1ng/

Related

Angular highcharts scroll not working while drag over the chart on mobile

I am using basic line Highcharts on my Angular 8 project. While I'm trying to use the system on the iPhone I can't scroll the page over the area where a chart is lying. Chart is preventing page scrolling from working. This is very annoying for instance when a chart is covering the whole screen, as there's no way to scroll the page in this case.
I am adding a code of my TS function
chartOptions = {
title: {
text: 'Your Net Worth'
},
yAxis: {
title: {
text: 'Money in GBP'
}
},
legend: {
align: 'center',
verticalAlign: 'bottom',
x: 0,
y: 0
},
credits: {
enabled: false,
},
plotOptions: {
series: {
label: {
connectorAllowed: false
},
pointStart: 2020
}
},
series: [
{
name: 'Net Worth',
color: '#00b300',
data: [latest_networth_for_chart]
}
, {
name: 'Age group (domestic) (coming soon)',
color: '#ff0000',
data: [0, 0, 0, 0, 0, 0, 0, 0],
visible: false
}, {
name: 'Age group (expats) (coming soon)',
color: '#0000b3',
data: [0, 0, 0, 0, 0, 0, 0, 0],
visible: false
},
{
name: 'Others in your industry (coming soon)',
color: '#0000b3',
data: [0, 0, 0, 0, 0, 0, 0, 0],
visible: false
},
{
name: 'Peer group (coming soon)',
color: '#0000b3',
data: [0, 0, 0, 0, 0, 0, 0, 0],
visible: false
},
{
name: 'Global average (coming soon)',
color: '#0000b3',
data: [0, 0, 0, 0, 0, 0, 0, 0],
visible: false
},
{
name: 'This time last year (coming soon)',
color: '#0000b3',
data: [0, 0, 0, 0, 0, 0, 0, 0],
visible: false
},
],
responsive: {
rules: [{
condition: {
maxWidth: 540
},
chartOptions: {
legend: {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom',
enabled: false
}
}
}]
}
}
}
Am I did anything wring on my code?
Regarts, Faz.

'Amcharts.isReady' is not working in angular6?

I am using amchart in my angular6 app with the help of following tutorial
amchart3-angular
But I need to show the graph after loaded all it's properties.How can I check whether the graph is ready to load in angular6?I tried with 'isReady' property of amchart.But it shows following error.
Cannot read property 'isReady' of undefined
app.component.ts
chart: AmChart;
ngAfterViewInit() {
this.chart = this.AmCharts.makeChart('chartdiv', {
'type': 'gauge',
'theme': 'light',
'dataProvider': [],
'axes': [{
'axisColor': 'transparent',
'color': '#fff',
'endValue': 7,
'gridInside': true,
'inside': true,
'radius': '100%',
'valueInterval': 1,
'tickColor': '#fff',
'pivotRadius': '0%',
'id': 'axes1',
'topText': 'RPM',
'topTextFontSize': 9,
'topTextYOffset': -20,
'topTextColor': '#fff',
'bottomTextYOffset': -3,
'bottomTextColor': '#fff',
'minorTickLength': 16,
'tickLength': 22,
'tickThickness': 2,
'labelOffset': 5,
'bands': [{
'color': '#f91f1f',
'endValue': 7,
'innerRadius': '87%',
'startValue': 5
},
{
'color': '#e60000',
'endValue': 0,
'startValue': 0,
'alpha': 0.3,
'radius': '100%',
'innerRadius': '15%',
},
{
'color': '#e60000',
'endValue': 0,
'startValue': 0,
'alpha': 0.6,
'radius': '100%',
'innerRadius': '15%',
},
]
}, {
'axisColor': '#fff',
'color': 'black',
'axisThickness': 3,
'endValue': 140,
'radius': '45%',
'valueInterval': 20,
'tickColor': 'black',
'axisAlpha': '0',
'bottomText': 'km/h',
'bottomTextFontSize': 9,
'bottomTextYOffset': -15,
'bottomTextColor': 'black',
'labelOffset': 2,
'tickThickness': 1.2,
'bands': [{
'color': '#fff',
'alpha': 1,
'startValue': 0,
'endValue': 220,
'radius': '100%',
'innerRadius': '0'
}]
}],
'arrows': [{
'color': '#ff0000',
'innerRadius': '6.3%',
'radius': '40%',
'startWidth': 3,
'value': 0,
}, {
'color': '#ff0000',
'innerRadius': '46%',
'radius': '90%',
'startWidth': 8,
'value': 0
},
{
'color': '#111',
'innerRadius': '7%',
'radius': '0',
'startWidth': 0,
'value': 0,
'nailAlpha': 1,
'nailRadius': 10
}
],
'export': {
'enabled': true
}
});
}
app.component.html
<div id="chartdiv" [style.width.%]="100" [style.height.px]="400">
in the above code I created the chart and store it in a variable having type 'Amchart' and displayed it in template with the help of 'id'. When I run the app the chart take little amount of time to show it in template. So that I need to show the graph only after it's initialization.How can I solve this issue?

Responsive Line Chart using High Charts & Bootstrap 3

Currently I have my HighChart Line Graph as follows:
<script language="javascript" type="text/javascript">
var highColors = [bgSystem, bgSuccess, bgWarning, bgPrimary];
// Chart data
var seriesData = [{
name: 'Total Accounts',
data: [5, 9, 12, 15, 17, 22, 28, 30, 34, 36, 38, 46]
}, {
name: 'Total Songs',
data: [2, 3, 4, 5, 8, 12, 17, 23, 30, 34, 44]
}, {
name: 'Total Recordings',
data: [15, 19, 22, 29, 32, 34, 36, 40, 42, 44, 45]
}, {
name: 'Total Writers',
data: [11, 13, 15, 18, 24, 28, 30, 34, 38, 40, 42, 45]
}];
var dashboardChart = $('#dashboard_chart');
if (dashboardChart.length) {
dashboardChart.highcharts({
credits: false,
colors: highColors,
chart: {
backgroundColor: 'white',
className: '',
type: 'line',
zoomType: 'x',
panning: true,
panKey: 'shift',
marginTop: 45,
marginRight: 1,
},
title: {
text: null
},
xAxis: {
gridLineColor: '#EEE',
lineColor: '#EEE',
tickColor: '#EEE',
categories: ['Jan', 'Feb', 'Mar', 'Apr',
'May', 'Jun', 'Jul', 'Aug',
'Sep', 'Oct', 'Nov', 'Dec'
]
},
yAxis: {
min: 0,
tickInterval: 5,
gridLineColor: '#EEE',
title: {
text: 'Total'
}
},
plotOptions: {
spline: {
lineWidth: 3,
},
area: {
fillOpacity: 0.2
}
},
exporting: {
enabled: false
},
legend: {
enabled: true,
floating: false,
align: 'right',
verticalAlign: 'top',
x: -5
},
series: seriesData
});
}
</script>
Here is how its displayed in my HTML
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div id="dashboard_chart" style="height: 500px; width:100%;"></div>
</div>
</div>
The main issue is that the graph does not fit the whole container for the tablet in both portrait and landscape. Does anyone have any suggestions? As to how I could make it responsive without adding in-line styles?
You can set options for responsive charts in high charts initialization. It allows you to specify different widths and height and you can specify different values such as hiding labels or showing something.
dashboardChart.highcharts({
options:values,
options:values,
....
....
responsive: {
rules: [{
condition: {
maxWidth: 500
},
chartOptions: {
legend: {
align: 'center',
verticalAlign: 'bottom',
layout: 'horizontal'
},
yAxis: {
labels: {
align: 'left',
x: 0,
y: -5
},
title: {
text: null
}
},
subtitle: {
text: null
},
credits: {
enabled: false
}
}
}]
}
})
Here's the link to their official docs : https://www.highcharts.com/demo/responsive

Transparent plot area of heatmap using highcharts

how to make a heatmap's plot area as transparent.
i would like to remove all the white blocks in the chart and make it transparent, so that background colors are visible.
refer this fiddle
$(function () {
$('#container').highcharts({
chart: {
type: 'heatmap',
marginTop: 40,
marginBottom: 40,
backgroundColor: {
linearGradient: { x1: 1, y1: 0, x2: 0, y2: 1 },
stops: [
[0.23, 'rgb(240, 59, 9)'],
[0.5, 'rgb(255, 224, 80)'],
[0.67, 'rgb(54, 64, 207)'],
[0.99, 'rgb(13, 163, 35)'],
[1, 'rgb(217, 186, 50']
]
},
},
title: {
text: 'Sales per employee per weekday'
},
xAxis: {
categories: ['Alexander', 'Marie', 'Maximilian', 'Sophia', 'Lukas', 'Maria', 'Leon', 'Anna', 'Tim', 'Laura']
},
yAxis: {
categories: ['< 1%', '2-10%', '11-50%', '51-90%', '91-100%'],
title: null
},
colorAxis: {
min: 0,
minColor: '#FFFFFF',
maxColor:'#FFFFFF'
//maxColor: Highcharts.getOptions().colors[0]
},
legend: {
align: 'right',
layout: 'vertical',
margin: 0,
verticalAlign: 'top',
y: 25,
symbolHeight: 320
},
tooltip: {
formatter: function () {
return '<b>' + this.series.xAxis.categories[this.point.x] + '</b> sold <br><b>' +
this.point.value + '</b> items on <br><b>' + this.series.yAxis.categories[this.point.y] + '</b>';
}
},
series: [{
name: 'Sales per employee',
borderWidth: 1,
data: [[0,0,0],[0,1,19],[0,2,8],[0,3,24],[0,4,67],[1,0,92],[1,1,58],[1,2,78],[1,3,117],[1,4,48],[2,0,35],[2,1,15],[2,2,123],[2,3,64],[2,4,52],[3,0,72],[3,1,132],[3,2,114],[3,3,19],[3,4,16],[4,0,38],[4,1,5],[4,2,8],[4,3,117],[4,4,115],[5,0,88],[5,1,32],[5,2,12],[5,3,6],[5,4,120],[6,0,13],[6,1,44],[6,2,88],[6,3,98],[6,4,96],[7,0,31],[7,1,1],[7,2,82],[7,3,32],[7,4,30],[8,0,85],[8,1,97],[8,2,123],[8,3,64],[8,4,84],[9,0,47],[9,1,114],[9,2,31],[9,3,48],[9,4,91]],
dataLabels: {
enabled: true,
color: 'black',
style: {
textShadow: 'none'
}
}
}]
});
});
Here is the fiddle solution
$(function () {
$('#container').highcharts({
chart: {
type: 'heatmap',
marginTop: 40,
marginBottom: 40,
plotBackgroundColor: {
linearGradient: { x1: 1, y1: 0, x2: 0, y2: 1 },
stops: [
[0.03, 'rgb(247, 88, 45)'],
[0.5, 'rgb(255, 224, 80)'],
[0.67, 'rgb(54, 64, 207)'],
[0.99, 'rgb(13, 163, 35)'],
[1, 'rgb(217, 186, 50']
]
}
},
title: {
text: 'Sales per employee per weekday'
},
xAxis: {
categories: ['Insignificant', 'Minimum', 'Significant', 'Material', 'Critical']
},
yAxis: {
categories: ['< 1%', '2-10%', '11-50%', '51-90%', '91-100%'],
title: null
},
colorAxis: {
min: 0,
minColor: 'transparent',
maxColor:'transparent'
//maxColor: Highcharts.getOptions().colors[0]
},
legend: {
align: 'right',
layout: 'vertical',
margin: 0,
verticalAlign: 'top',
y: 25,
symbolHeight: 320
},
tooltip: {
formatter: function () {
return '<b>' + this.series.xAxis.categories[this.point.x] + '</b> sold <br><b>' +
this.point.value + '</b> items on <br><b>' + this.series.yAxis.categories[this.point.y] + '</b>';
}
},
series: [{
name: 'Sales per employee',
borderWidth: 1,
data: [[0,0,0],[0,1],[0,2,8],[0,3,24],[0,4,67],[1,0,92],[1,1,58],[1,2,78],[1,3,117],[1,4,48],[2,0,35],[2,1,15],[2,2,123],[2,3,64],[2,4,52],[3,0,72],[3,1,132],[3,2,114],[3,3,19],[3,4,16],[4,0,38],[4,1,5],[4,2,8],[4,3,117],[4,4,115]],
dataLabels: {
enabled: true,
color: 'black',
style: {
textShadow: 'none'
}
}
}]
});
});

Highchart speedometer take input from csv

I am trying to read the data from csv and display it as a input to Speedometer but I am unable to get the chart. Please tell me where i am going wrong.
My code is:
$(document).ready(function() {
var options = {
chart: {
type: 'gauge',
plotBackgroundColor: null,
plotBackgroundImage: null,
plotBorderWidth: 0,
plotShadow: false
},
title: {
text: 'Speedometer'
},
pane: {
startAngle: -150,
endAngle: 150,
background: [{
backgroundColor: {
linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
stops: [
[0, '#FFF'],
[1, '#333']
]
},
borderWidth: 0,
outerRadius: '109%'
}, {
backgroundColor: {
linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
stops: [
[0, '#333'],
[1, '#FFF']
]
},
borderWidth: 1,
outerRadius: '107%'
}, {
// default background
}, {
backgroundColor: '#DDD',
borderWidth: 0,
outerRadius: '105%',
innerRadius: '103%'
}]
},
// the value axis
yAxis: {
min: 0,
max: 100,
minorTickInterval: 'auto',
minorTickWidth: 1,
minorTickLength: 10,
minorTickPosition: 'inside',
minorTickColor: '#666',
tickPixelInterval: 30,
tickWidth: 2,
tickPosition: 'inside',
tickLength: 10,
tickColor: '#666',
labels: {
step: 2,
rotation: 'auto'
},
title: {
text: 'km/h'
},
plotBands: [{
from: 0,
to: 120,
color: '#55BF3B' // green
}, {
from: 120,
to: 160,
color: '#DDDF0D' // yellow
}, {
from: 160,
to: 200,
color: '#DF5353' // red
}]
},
series: []
};
$.get('data.csv', function(data) {
var series = {
data: [],
name: 'Speed',
tooltip: {
valueSuffix: ' km/h'
}
};
series.data.push(parseFloat(data));
options.series.push(series);
alert("data "+options.series);
var chart = new Highcharts.Chart(options);
});
});
and the csv file is simple
data.csv has only one value 30.
or incase it is
t1,30
t2,40
t3,60
how do i display 3 corresponding speedometers with respective speed.
Your help is greatly appreciated.
Thanks in advance.
In your case data your data (from ajax) is a single string, but you need to split elements and then choose which should be parsed to integer (parseFloat).