From the servlet I am getting back 3 arrays activeArray,inActiveArray and rejectedArray. I would like to pick these arrays in the java script and come up with a high charts that plots the categories as the blood group names like A+, A- etc.
The series names will be Active, Inactive and rejected.
The series data will have to be the arrays mentioned above.
I was able to achieve only the categories but the series data does not get plotted. I have included the script code below.
<script>
var nameArray ="${nameArray}";
var bloodNames = [
<c:forEach items="${nameArray}" var="name">
'<c:out value="${name}" />',
</c:forEach>
];
var activeValue = new Array();
activeValue = [
<c:forEach items="${activeArray}" var="data">
'<c:out value="${data}" />',
</c:forEach>
];
var seriesData = [
{
name: 'Active',
data:activeValue
},{
name:'InActive',
data:[3, 01, 03,0,0,0]
},
{
name:'Rejected',
data:[4, 01, 03,0,2,0]
}
]
$(function () {
var myChart = Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: 'Donar Status Report'
},
subtitle: {
text: 'Blood Name Wise'
},
xAxis: {
categories:
bloodNames
,
crosshair: true
},
yAxis: {
min: 0,
title: {
text: 'Person (in Counts)'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: seriesData
});
});
The quotes around the data in the active is the problem. The column chart expecting an integer as data.
You can use Map function to convert array of string to array of number.Rest of your chart is ok
var activeValue= ["1","3","2","2","1","2","0","1","0","0"]
activeValue=activeValue.map(Number)
console.log(activeValue)
Related
I'm getting this error Type 'number' has no properties in common with type 'XrangePointOptionsObject'. I want to add bar chart using angular highchatrs in my angular project but I'm not able to add because of this error. So can you please help me to solve this error.
Thanks.
this is my component.ts file
import { Chart } from 'angular-highcharts';
import * as Highcharts from 'highcharts'
#Component({
selector: 'app-bar-chart',
templateUrl: './bar-chart.component.html',
styleUrls: ['./bar-chart.component.scss']
})
export class BarChartComponent implements OnInit {
orderChart: Chart;
revenueChart: Chart;
options: Highcharts.Options;
constructor() { }
ngOnInit() {
this.init();
}
init() {
this.options = {
chart: {
type: 'column'
},
title: {
text: 'Total Predected Vs Actual'
},
xAxis:{
categories: ['2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017'],
crosshair: true
},
yAxis : {
min: 0 ,
},
tooltip : {
headerFormat: '<span style = "font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style = "color:{series.color};padding:0">{series.name}: </td>' +
'<td style = "padding:0"><b>{point.y:.1f} mm</b></td></tr>', footerFormat: '</table>',
shared: true, useHTML: true
},
plotOptions : {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [
{
name: "Predected",
data :[14,17,9,10,6,19,6,8]
},
{
name: "Actual",
data: [65,74,44,66,9,23,36,51]
}
]
};
let orderChart = new Chart(this.options);
this.orderChart = orderChart;
let revenueChart = new Chart(this.options);
this.revenueChart = revenueChart;
}
}
so the error is shown on the data in the series.
I was facing the same issue. you need to use following input
[runOutsideAngular]="true"
so it will be
<highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions.trends" [runOutsideAngular]="true"
style="width: 100%; height: 400px; display: block;">
</highcharts-chart>
I'm getting this error Type 'number' has no properties in common with type 'XrangePointOptionsObject'. I want to add bar chart using angular highchatrs in my angular project but I'm not able to add because of this error. So can you please help me to solve this error.
Thanks.
this is my component.ts file
import { Chart } from 'angular-highcharts';
import * as Highcharts from 'highcharts'
#Component({
selector: 'app-bar-chart',
templateUrl: './bar-chart.component.html',
styleUrls: ['./bar-chart.component.scss']
})
export class BarChartComponent implements OnInit {
orderChart: Chart;
revenueChart: Chart;
options: Highcharts.Options;
constructor() { }
ngOnInit() {
this.init();
}
init() {
this.options = {
chart: {
type: 'column'
},
title: {
text: 'Total Predected Vs Actual'
},
xAxis:{
categories: ['2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017'],
crosshair: true
},
yAxis : {
min: 0 ,
},
tooltip : {
headerFormat: '<span style = "font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style = "color:{series.color};padding:0">{series.name}: </td>' +
'<td style = "padding:0"><b>{point.y:.1f} mm</b></td></tr>', footerFormat: '</table>',
shared: true, useHTML: true
},
plotOptions : {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [
{
name: "Predected",
data :[14,17,9,10,6,19,6,8]
},
{
name: "Actual",
data: [65,74,44,66,9,23,36,51]
}
]
};
let orderChart = new Chart(this.options);
this.orderChart = orderChart;
let revenueChart = new Chart(this.options);
this.revenueChart = revenueChart;
}
}
so the error is shown on the data in the series.
I was facing the same issue. you need to use following input
[runOutsideAngular]="true"
so it will be
<highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions.trends" [runOutsideAngular]="true"
style="width: 100%; height: 400px; display: block;">
</highcharts-chart>
I'm using Highmaps to show the number of relevant users from each individual country. This should then be displayed in a gradient, so that the more users there are from a country, the darker the color. I have it running in Highmaps so that it loads the data, but for some reason it's displaying all the countries in black, despite the gradient legend being white to blue. Any idea why that is? Thanks!
$(document).ready(function(){
// Basic highcharts initialization
Highcharts.setOptions({
lang: {
thousandsSep: ','
}
});
var analytics_map = new AnalyticsMap('#container');
analytics_map.setTitle('# of Signups');
analytics_map.load([
["AE","31"],
["AR","51"],
["AT","71"],
["AU","81"],
["BE","91"],
["BG","9"],
["BO","22"],
["BR","37"],
["US","173"],
["UY","5"],
["ZA","19"]
]);
function AnalyticsMap(selector){
this.selector = selector,
this.title = 'Default Title',
this.setTitle = function (title){
this.title = title;
},
this.load = function(data){
$(this.selector).highcharts('Map', {
title: {
text: this.title
},
mapNavigation: {
enabled: true,
buttonOptions: {
verticalAlign: 'bottom'
}
},
colorAxis: {
},
series: [{
data: data,
mapData: Highcharts.maps['custom/world'],
joinBy: ['iso-a2', 0],
keys: ['iso-a2', 'value'],
name: this.title,
dataLabels: {
//enabled: true,
//format: '{point.code}'
},
tooltip: {
pointFormat: '{point.iso-a2}: {point.value} signups'
}
}]
});
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/maps/highmaps.js"></script>
<script src="https://code.highcharts.com/mapdata/custom/world.js"></script>
<div id="container"></div>
You have an issue with the datatypes.
Do not convert your integers to strings by putting quotes around them.
var data = [
['DE.SH', 728],
['DE.BE', 710],
['DE.MV', 963],
['DE.HB', 541],
['DE.HH', 622],
['DE.RP', 866],
['DE.SL', 398],
['DE.BY', 785],
['DE.SN', 223],
['DE.ST', 605],
['DE.NW', 237],
['DE.BW', 157],
['DE.HE', 134],
['DE.NI', 136],
['DE.TH', 704],
['DE.', 361]
];
I am attempting to write a function to add a highchart to a page and a function that can update the data for that chart based on a streaming API. I added a setInterval to simulate the streaming api.
The issue occurs on line 80. I believe it is because I have not set the series array with the chart object properly. When I need to add new data via 'addPoint', the prototype is not there. What am I missing in my AddChart function that wires the series up to highcharts?
FIDDLE:
http://jsfiddle.net/puto3Lg0/2/
$(function () {
$(document).ready(function () {
var metrics = [];
Highcharts.setOptions({
global: {
useUTC: false
}
});
function AddChart(metric) {
$("#divMain").append('<div id="' + metric.key + '" style="min-width: 310px; height: 200px; margin: 0 auto"></div>');
$('#' + metric.key).highcharts({
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
},
title: {
text: metric.Title
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Messages'
},
plotLines: [
{
value: 0,
width: 1,
color: '#808080'
}
]
},
tooltip: {
formatter: function() {
return '<b>' + this.series.name + '</b><br/>' +
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: metric.series
});
};
function ParseData(message) {
var jsonObj = JSON.parse(message);
$.each(jsonObj.Metrics, function(index, value) {
var metricName = value.Metric.Name.replace(' ', '');
if (metrics[metricName] == undefined) {
metrics[metricName] = {
"title": value.Metric.Name,
"key": metricName,
"series": [
{
name: value.Metric.Name,
data: []
}
],
}
AddChart(metrics[metricName]);
}
metrics[metricName].series.addPoint([new Date().getTime(), parseInt(value.Metric.CurrentValue)], true, false);
});
};
setInterval(function () {
var m = "{\"Metrics\": [{\"Metric\":{\"Name\":\"Queue 01\",\"CurrentValue\":\"0\",\"TimeStamp\":\"\\\x2FDate(1415826323291)\\\x2F\"}},{\"Metric\":{\"Name\":\"Queue 02\",\"CurrentValue\":\"3\",\"TimeStamp\":\"\\\x2FDate(1415826323344)\\\x2F\"}},{\"Metric\":{\"Name\":\"Queue 03\",\"CurrentValue\":\"9\",\"TimeStamp\":\"\\\x2FDate(1415826323405)\\\x2F\"}}]}";
ParseData(m);
}, 1000);
});
});
First, you have metrics declared as an array. Should be an empty object:
var metrics = {};
Second, the data structure you've created, metrics[metricName].series is not a Highcharts series object. It's an object you created and used to supply Highcharts data. To get the real series object, you'll have to get it back from the chart.
// getting the chart from the DOM, then the first series...
$("#"+metricName).highcharts().series[0].addPoint([new Date().getTime(), parseInt(value.Metric.CurrentValue)], true, false);
Updated fiddle.
I am trying to output JSON data on to Highstock chart. Initially I struggled with the JSON formatted date which I resolved by following instruction on other answer on stackoverflow by re-formatting dates. But I'm still unable to get the graph plotted on view page -
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var mydata =[];
chartOjb = new Object();
$.ajax({
type: "GET",
url: "/ReportIntance/DummyCall/2",
data: '{ }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$.each(data, function (index, item) {
chartOjb.name = new Date(parseInt(item.DayDate.replace("/Date(", "").replace(")/", ""), 10));
chartOjb.data = item.Series1;
mydata.push({
x: new Date(parseInt(item.DayDate.replace("/Date(", "").replace(")/", ""), 10)),
y: item.Series1
});
})
},
failure: function (response) {
alert(response);
}
});
chart1 = new Highcharts.Chart({
chart: {
renderTo: 'Chart1'
},
title: {
text: 'Delivery Price example using Chart'
},
xAxis: {
type: 'datetime'
},
yAxis: {
title: {
text: 'Price'
}
},
series: [ { data: mydata }]
});
});
</script>
<div id="Chart1" style="height: 500px; min-width: 500px"></div>
My JSON string is -
[{"DayDate":"\/Date(1334704500000)\/","Series1":4.01,"Series2":0,"Series3":0,"Series4":0,"Series5":0},
{"DayDate":"\/Date(1334705400000)\/","Series1":5.01,"Series2":0,"Series3":0,"Series4":0,"Series5":0},
{"DayDate":"\/Date(1334706300000)\/","Series1":4.51,"Series2":0,"Series3":0,"Series4":0,"Series5":0},
{"DayDate":"\/Date(1334707200000)\/","Series1":6.01,"Series2":0,"Series3":0,"Series4":0,"Series5":0},
{"DayDate":"\/Date(1334708100000)\/","Series1":4.71,"Series2":0,"Series3":0,"Series4":0,"Series5":0},
{"DayDate":"\/Date(1334709000000)\/","Series1":7.01,"Series2":0,"Series3":0,"Series4":0,"Series5":0},
{"DayDate":"\/Date(1334709900000)\/","Series1":7.01,"Series2":0,"Series3":0,"Series4":0,"Series5":0}]
Currently I'm trying to output simple line chart and using only DayDate (X-axis) and 'Series1' as Y-axis.
Highstock chart shows just 'x axis' but no line graph or y axis is shown.
Can someone point me what I'm doing wrong? Any help will be appreciated.
Edit:
After setting turboThresold field I can now see the X Axis on my highstock chart. However values from y axis are still missing.
This is how graph looks without any y axis lines. The data seems to be correct
Here's my updated code -
$(function () {
var mydata = [];
chartOjb = new Object();
// See source code from the JSONP handler at https://github.com/highslide-software/highcharts.com/blob/master/samples/data/from-sql.php
$.getJSON('/ReportIntance/DummyCall/2', function (data) {
// Add a null value for the end date
//data = [].concat(data, [[Date.UTC(2013, 9, 14, 19, 59), null, null, null, null]]);
$.each(data, function (index, item) {
chartOjb.name = new Date(parseInt(item.DayDate.replace("/Date(", "").replace(")/", ""), 10));
chartOjb.data = item.Series1;
mydata.push({ x: chartOjb.name, y: parseFloat(chartOjb.data) });
//alert(chartOjb.name + "/" + chartOjb.data);
});
// create the chart
$('#container').highcharts('StockChart', {
chart: {
//type: 'candlestick',
zoomType: 'x'
},
navigator: {
adaptToUpdatedData: false,
series: {
data: mydata
}
},
scrollbar: {
liveRedraw: false
},
title: {
text: 'Historical prices from June 2012'
},
subtitle: {
text: 'Displaying 20K records using Highcharts Stock by using JSON'
},
plotOptions: {
line: {
turboThreshold: 20450
}
},
xAxis: {
type: 'datetime',
title: 'Time',
minRange: 3600 * 1000/15 // one hour
},
yAxis:{
title: {
text: 'Prices',
style: {
color: '#89A54E'
}
},
lineWidth: 1,
opposite: false,
showEmpty: false //hides empty data series
},
series: [{
data: data,
pointStart: Date.UTC(2012, 6, 1), // first of June
pointInterval: 3600 * 1000/15,
dataGrouping: {
enabled: false
}
}]
});
});
});
Thanks to Sebastian, I can now see the graphs. Only issue I had was that I wasn't pointing to correct 'data' Your suggestion to not convert to datetime improved the performance