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?
Related
I'm working through adding the ChartJS library to a Node web app and am having trouble dynamically passing through data from a "Player" model. Here's the script tag portion of the EJS template:
<script>
let myChart = document.getElementById('myChart').getContext('2d');
let pointAvg = [1, 2, 3, 4]
console.log(pointAvg)
let playerStatChart = new Chart(myChart, {
type: 'bar',
data: {
labels: ['Freshman', 'Sophomore', 'Junior', 'Senior'],
datasets: [{
label: 'Points',
data: pointAvg,
backgroundColor: 'rgb(149,16,16, 0.4)',
borderWidth: 1,
borderColor: '#000',
hoverBorderWidth: 3,
hoverBorderColor: '#000'
}]
},
options: {
title: {
display: true,
text: "Points: <%= player.name %>",
fontSize: 25
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
</script>
And here's an example of a "player" in the Player model:
_id: 5e94ac2d81fa5428b0323fc1,
name: 'Naz Mitrou-Long',
season: [
{
year: '2012-2013',
grade: 'Freshman',
gp: 18,
gs: 0,
mpg: 6.9,
fg: 0.348,
tp: 0.278,
ft: 1,
rpg: 0.8,
apg: 1,
spg: 0.3,
bpg: 0,
ppg: 1.4
},
{
year: '2013-2014',
grade: 'Sophomore',
gp: 36,
gs: 7,
mpg: 20.3,
fg: 0.432,
tp: 0.4,
ft: 0.643,
rpg: 1.6,
apg: 1.1,
spg: 0.2,
bpg: 0.1,
ppg: 7.1
},
{
year: '2014-2015',
grade: 'Junior',
gp: 34,
gs: 33,
mpg: 27.5,
fg: 0.449,
tp: 0.391,
ft: 0.755,
rpg: 2.9,
apg: 2,
spg: 0.8,
bpg: 0.1,
ppg: 10.1
},
{
year: '2015-2016',
grade: 'R. Senior',
gp: 8,
gs: 8,
mpg: 31.6,
fg: 0.425,
tp: 0.291,
ft: 0.6,
rpg: 2.9,
apg: 1.9,
spg: 0.6,
bpg: 0.3,
ppg: 12
},
{
year: '2016-2017',
grade: 'Senior',
gp: 35,
gs: 35,
mpg: 33.3,
fg: 0.473,
tp: 0.384,
ft: 0.795,
rpg: 4.6,
apg: 2.7,
spg: 1.2,
bpg: 0,
ppg: 15.1
}
]
This player data has already been passed through to the client side from the Node server and is available for use. Currently I pass through other values to the template like so:
<h1><%= player.name %></h1>
How can I populate that static pointAvg array with the ppg from each object in the season array and make it dynamic instead?
<script>
var vPlayer = '<%- JSON.stringify(player) %>';
console.log(vPlayer);
</script>
Now you have the model data. Use it as you want.
If you are sending data from nodejs into client side script tag with EJS. Use this method.
<script>
let data='<%- JSON.stringify(player) %>';
data= JSON.parse(data);
</script>
Stringify will return your Object string-ed. Parse will convert it back into an Object for further use.
Im trying to assign this process to a function so I can add a listener to a button but it keeps giving me an "Uncaught SyntaxError: missing ) after argument list". Can anyone steer me in the right direction?
function popWindow() {
Ext.create('Ext.window.Window', {
bodyStyle: "background-color:#FFFFFF",
title: 'QA Tools',
height: 300,
width:400,
layout: 'absolute',
items: [{
xtype: 'button',
x: 15,
y: 35,
height: 35,
width: 125,
text: 'Sell Listings',
itemId: 'sellBtn',
}, {
xtype: 'button',
x: 15,
y: 90,
height: 35,
width: 125,
text: 'Set SP Cycle to 1 Min',
itemId: 'sp1MinBtn',
}, {
xtype: 'button',
x: 15,
y: 145,
height: 35,
width: 175,
text: 'Set Single AP Cycle to 1 min',
itemId: 'singleAPMinBtn',
}, {
xtype: 'button',
x: 15,
y: 200,
height: 35,
width: 175,
text: 'Set Grouped AP Cycle to 1 min',
itemId: 'groupedAPMinBtn',
}, {
xtype: 'textfield',
x: 170,
y: 36,
height: 30,
width: 175,
allowBlank: false,
minLength: 7,
maxLength: 7,
emptyText: 'Enter Listing ID',
itemId: 'sellListingField',
}]
}
}).show();
Can anyone help me get this to work?
Yes, your JavaScript is not valid. Usually a warning like that means you have some malformed code. I recommend running it through a prettifier like this one to help line the braces up and find the problem. When we do that with your code, we see 2 mistakes.
You don't close out of the function with an ending brace
You have 1 too many braces before the .show
It should look like this
function popWindow() {
Ext.create('Ext.window.Window', {
bodyStyle: "background-color:#FFFFFF",
title: 'QA Tools',
height: 300,
width: 400,
layout: 'absolute',
items: [{
xtype: 'button',
x: 15,
y: 35,
height: 35,
width: 125,
text: 'Sell Listings',
itemId: 'sellBtn',
}, {
xtype: 'button',
x: 15,
y: 90,
height: 35,
width: 125,
text: 'Set SP Cycle to 1 Min',
itemId: 'sp1MinBtn',
}, {
xtype: 'button',
x: 15,
y: 145,
height: 35,
width: 175,
text: 'Set Single AP Cycle to 1 min',
itemId: 'singleAPMinBtn',
}, {
xtype: 'button',
x: 15,
y: 200,
height: 35,
width: 175,
text: 'Set Grouped AP Cycle to 1 min',
itemId: 'groupedAPMinBtn',
}, {
xtype: 'textfield',
x: 170,
y: 36,
height: 30,
width: 175,
allowBlank: false,
minLength: 7,
maxLength: 7,
emptyText: 'Enter Listing ID',
itemId: 'sellListingField',
}]
}).show();
}
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
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/
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).