DrillDown Column chart to Stacked Column chart in Highcharts using Angular 5 - highcharts

I need to drilldown from a single series Column chart to stacked column chart (using Highcharts) in Angular 5, is there any example/demo?
component.ts
this.chart41 = new Chart({
chart: {
type: 'column'
},
xAxis: {
type: 'category'
},
plotOptions: {
column: {
cursor: 'pointer',
point: {
events: {
}
}
}
},
tooltip: {
headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>'
},
series: [
{
name: "Days",
// colorByPoint: true,
data: [
{
name: "6-May",
y: 62.74,
drilldown: "6-May"
},
{
name: "7-May",
y: 10.57,
drilldown: "7-May"
},
{
name: "8-May",
y: 7.23,
drilldown: "8-May"
},
{
name: "9-May",
y: 5.58,
drilldown: "6-May"
},
{
name: "10-May",
y: 4.02,
drilldown: "10-May"
},
{
name: "11-May",
y: 1.92,
drilldown: "11-May"
},
{
name: "12-May",
y: 7.62,
drilldown: "12-May"
}
]
}
],
drilldown: {
series: [
{
name: "6-May",
id: "6-May",
data: [
[
"P1",
12
],
[
"P2",
12
],
[
"P3",
12
],
[
"P4",
12
]
]
},
{
name: "7-May",
id: "7-May",
data: [
[
"P1",
0.1
],
[
"P2",
1.3
],
[
"P3",
53.02
],
[
"P4",
1.4
]
]
},
{
name: "8-May",
id: "8-May",
data: [
[
"P1",
0.1
],
[
"P2",
1.3
],
[
"P3",
53.02
],
[
"P4",
1.4
]
]
},
{
name: "9-May",
id: "9-May",
data: [
[
"P1",
0.1
],
[
"P2",
1.3
],
[
"P3",
53.02
],
[
"P4",
1.4
]
]
},
{
name: "10-May",
id: "10-May",
data: [
[
"P1",
0.1
],
[
"P2",
1.3
],
[
"P3",
53.02
],
[
"P4",
1.4
]
]
},
{
name: "11-May",
id: "11-May",
data: [
[
"P1",
0.1
],
[
"P2",
1.3
],
[
"P3",
53.02
],
[
"P4",
1.4
]
]
},
{
name: "12-May",
id: "12-May",
data: [
[
"P1",
0.1
],
[
"P2",
1.3
],
[
"P3",
53.02
],
[
"P4",
1.4
]
]
}
]
}
});
The view is something like this -
On clicking on any column(say 6-May), it shows the drill-down of column chart for 6-May -
I want to show a stacked column chart in the drilled down chart (as of now there is only legend i.e 6-May).

Related

Highcharts conditional DrillDown not hiding DrillUp Button

I'm trying to avoid the chart's drilldown when the user clicks the x-Axis label, but, unless I'm doing something wrong, the DrillUpButton doesn't dissapear completly when I cancel the event:
chart: {
type: "column",
events: {
drilldown: function (e)
{
if (e.category != null)
return false;
}
}
}
http://jsfiddle.net/ar3k9wda/3/
Is this a bug??? Or what else do I need to do???
You want to disable data label click. check this post it will be help full
Highcharts.Tick.prototype.drillable = function () {};
// Create the chart
Highcharts.chart('container', {
chart: {
type: "column",
/*events: {
drilldown: function (e)
{
if (e.category != null)
return false;
}
}*/
},
xAxis: {
type: 'category'
},
legend: {
enabled: false
},
series: [{
name: 'Brands',
colorByPoint: true,
data: [{
name: 'Microsoft Internet Explorer',
y: 56.33,
drilldown: 'Microsoft Internet Explorer'
}, {
name: 'Chrome',
y: 24.03,
drilldown: 'Chrome'
}, {
name: 'Firefox',
y: 10.38,
drilldown: 'Firefox'
}, {
name: 'Safari',
y: 4.77,
drilldown: 'Safari'
}, {
name: 'Opera',
y: 0.91,
drilldown: 'Opera'
}, {
name: 'Proprietary or Undetectable',
y: 0.2,
drilldown: null
}]
}],
drilldown: {
series: [{
name: 'Microsoft Internet Explorer',
id: 'Microsoft Internet Explorer',
data: [
[
'v11.0',
24.13
],
[
'v8.0',
17.2
],
[
'v9.0',
8.11
],
[
'v10.0',
5.33
],
[
'v6.0',
1.06
],
[
'v7.0',
0.5
]
]
}, {
name: 'Chrome',
id: 'Chrome',
data: [
[
'v40.0',
5
],
[
'v41.0',
4.32
],
[
'v42.0',
3.68
],
[
'v39.0',
2.96
],
[
'v36.0',
2.53
],
[
'v43.0',
1.45
],
[
'v31.0',
1.24
],
[
'v35.0',
0.85
],
[
'v38.0',
0.6
],
[
'v32.0',
0.55
],
[
'v37.0',
0.38
],
[
'v33.0',
0.19
],
[
'v34.0',
0.14
],
[
'v30.0',
0.14
]
]
}, {
name: 'Firefox',
id: 'Firefox',
data: [
[
'v35',
2.76
],
[
'v36',
2.32
],
[
'v37',
2.31
],
[
'v34',
1.27
],
[
'v38',
1.02
],
[
'v31',
0.33
],
[
'v33',
0.22
],
[
'v32',
0.15
]
]
}, {
name: 'Safari',
id: 'Safari',
data: [
[
'v8.0',
2.56
],
[
'v7.1',
0.77
],
[
'v5.1',
0.42
],
[
'v5.0',
0.3
],
[
'v6.1',
0.29
],
[
'v7.0',
0.26
],
[
'v6.2',
0.17
]
]
}, {
name: 'Opera',
id: 'Opera',
data: [
[
'v12.x',
0.34
],
[
'v28',
0.24
],
[
'v27',
0.17
],
[
'v29',
0.16
]
]
}]
}
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/drilldown.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

Highcharts zones fail to work correctly with yAxis min max values set

Highcharts 5.x.x
I setup zones on a series of data to stop a solid line being drawn at value 0.
This works fine when the yAxis.min and yAxis.max properties are not defined, however after setting those two properties the zones are ignore and a solid line appears.
Toggle comment the yAxis config.
Example
Highcharts.chart('container', {
yAxis: { min: 0, max: 100 },
xAxis: { type: 'datetime' },
series: [
{
data: [
[
1499249640000,
0.003
],
[
1499249700000,
1.9205
],
[
1499249760000,
1.9611
],
[
1499249820000,
1.928
],
[
1499249880000,
0.943
],
[
1499249940000,
0.944
],
[
1499250000000,
0.952
],
[
1499250060000,
0.044
],
[
1499250120000,
0.961
]
],
type: 'area'
},{
zones: [{
value: 0.01,
color: 'rgb(255, 255, 255, 0)'
}],
data: [
[
1499249640000,
0
],
[
1499249700000,
0
],
[
1499249760000,
1.9611
],
[
1499249820000,
0
],
[
1499249880000,
0.943
],
[
1499249940000,
0
],
[
1499250000000,
0
],
[
1499250060000,
0
],
[
1499250120000,
0
]
],
type: 'line'
}]
});

How to use PlotLines only for drilldown option?

I have used Column with drilldown highchart.
and its drilldown is
I am getting the right output in its drilldown but I don't want PlotLine to be visible in the first image. How do I solve this?
$(document).ready(function () { });
angular.module('myModule', []).service("AttendanceService", function ($http) {
this.getdata = function () {
return $http({
method: "post",
url: "GetAttendanceReport",
params: [{ EmpID: $("#nameofEmp").val(), YearID: $("#YearIn").val() }],
dataType: "json"
});
};
}).controller('myController', function ($scope,AttendanceService) {
GetAlldata();
function GetAlldata() {
var getAttendanceData = AttendanceService.getdata();
getAttendanceData.then(function (Attendances) {
Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: 'Attendance Report' + ' ' + $("#YearIn option:selected").text()
},
xAxis: {
type: 'category'
},
yAxis: {
title: {
text: 'Total Attendance Recorded'
},
plotLines: [{
value: 8,
color: '#ff0000',
width: 2,
zIndex: 4,
label: { text: 'goal' },
}],
},
legend: {
enabled: false
},
plotOptions: {
series: {
borderWidth: 0,
dataLabels: {
enabled: true,
format: '{point.y:.2f}'
}
}
},
tooltip: {
headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}mins</b> of total<br/>'
},
series: [{
name: 'Attendance',
colorByPoint: true,
data: [{
name: 'Jan',
y: Attendances.data.YearlyReport[0],
drilldown: 'Jan'
}, {
name: 'Feb',
y: Attendances.data.YearlyReport[1],
drilldown: 'Feb'
}, {
name: 'March',
y: Attendances.data.YearlyReport[2],
drilldown: 'March'
}, {
name: 'April',
y: Attendances.data.YearlyReport[3],
drilldown: 'April'
}, {
name: 'May',
y: Attendances.data.YearlyReport[4],
drilldown: 'May'
}, {
name: 'June',
y: Attendances.data.YearlyReport[5],
drilldown: 'June'
}, {
name: 'July',
y: Attendances.data.YearlyReport[6],
drilldown: 'July'
}, {
name: 'Aug',
y: Attendances.data.YearlyReport[7],
drilldown: 'Aug'
}, {
name: 'Sep',
y: Attendances.data.YearlyReport[8],
drilldown: 'Sep'
}, {
name: 'Oct',
y: Attendances.data.YearlyReport[9],
drilldown: 'Oct'
}, {
name: 'Nov',
y: Attendances.data.YearlyReport[10],
drilldown: 'Nov'
}, {
name: 'Dec',
y: Attendances.data.YearlyReport[11],
drilldown: 'Dec'
}]
}],
drilldown: {
series:
[{
name: 'Jan',
id: 'Jan',
data: [
[
'1',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 1])
],
[
'2',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 2])
],
[
'3',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 3])
],
[
'4',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 4])
],
[
'5',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 5])
],
[
'6',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 6])
],
[
'7',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 7])
],
[
'8',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 8])
],
[
'9',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 9])
],
[
'10',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 10])
],
[
'11',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 11])
],
[
'12',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 12])
],
[
'13',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 13])
],
[
'14',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 14])
],
[
'15',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 15])
],
[
'16',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 16])
],
[
'17',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 17])
],
[
'18',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 18])
],
[
'19',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 19])
],
[
'20',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 20])
],
[
'21',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 21])
],
[
'22',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 22])
],
[
'23',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 23])
],
[
'24',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 24])
],
[
'25',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 25])
],
[
'26',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 26])
],
[
'27',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 27])
],
[
'28',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 28])
],
[
'29',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 29])
],
[
'30',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 30])
],
[
'31',
parseFloat(Attendances.data.MonthlyReport[1 * 33 + 31])
]
]},and so on]
}
});
}, function () {
alert('Error in getting records');
});
} $("#btnLoad").click(function (event) {
GetAlldata();
});
$("#btnBack").click(function (event) {
window.location.href = "homepage";
});
});
This is the full code I have used.
You could remove and add plotLine dynamically when drilling down or up.
Example: http://jsfiddle.net/a5yzsarx/
$(function() {
$('#container').highcharts({
chart: {
events: {
drilldown: function() {
this.xAxis[0].removePlotLine('p1');
},
drillup: function() {
this.xAxis[0].addPlotLine({
id: 'p1',
value: 8,
color: '#ff0000',
width: 2,
zIndex: 4,
label: {
text: 'goal'
}
});
}
}
},
series: [{
type: 'column',
data: [{
y: 42,
drilldown: 's2'
}]
}],
drilldown: {
series: [{
id: 's2',
data: [1, 2, 3]
}]
},
yAxis: {
plotLines: [{
id: 'p1',
value: 8,
color: '#ff0000',
width: 2,
zIndex: 4,
label: {
text: 'goal'
}
}]
}
});
});

In highcharts, how do I get all categories showing with multiple series and xAxis type set to category?

I have a column chart that I am trying to get it to render multiple series with multiple categories. An because I am configuring the highchart via json I want to avoid having to set the categories in a separate location as the data. I found that if you set the xAxis.type to 'category' it will look in the series data for the categories. However, when I do this with multiple series and categories the categories get kinda messed up. How do I get this working so that all the categories are showing up appropriately? Pear is twice and Apple does not even appear.
$(function () {
$('#container').highcharts({
"title": {
"text": ""
},
"chart": {
"height": 400
},
xAxis: {
type: 'category'
},
"series": [
{
"name": "East",
"type": "column",
"data": [
{
name: 'Apple',
"y": 98.9
},
{
name: 'Apricot',
"y": 66.71
},
{
name: 'Cherry',
"y": 33.77
},
{
name: 'Pear',
"y": 362.24
},
{
name: 'Orange',
"y": 48.9
}
],
"_colorIndex": 0
},
{
"name": "West",
"type": "column",
"data": [
{
name: 'Peach',
"y": 348.83
},
{
name: 'Pear',
"y": 181.78
},
{
name: 'Lemon',
"y": 760.83
}
],
"_colorIndex": 1
}
]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
See fiddler: http://jsfiddle.net/vb8zz9ma/3/
Highcharts lib doesn't match categories in different series and doesn't sort data. Example using x indexes for second series (first one may remain as is): http://jsfiddle.net/vb8zz9ma/4
Example:
"series": [
{
"name": "East",
"type": "column",
"data": [
{
name: 'Apple',
"y": 98.9
},
{
name: 'Apricot',
"y": 66.71
},
{
name: 'Cherry',
"y": 33.77
},
{
name: 'Pear',
"y": 362.24
},
{
name: 'Orange',
"y": 48.9
}
],
"_colorIndex": 0
},
{
"name": "West",
"type": "column",
"data": [
{
name: 'Peach',
"y": 348.83,
x: 5
},
{
name: 'Pear',
"y": 181.78,
x: 3
},
{
name: 'Lemon',
"y": 760.83,
x: 6
}
],
"_colorIndex": 1
}
]

Plotting multiple points in highchart timeseries

I have data that looks like this in JSON format. I have two data series with same time line. When I try to plot them in highstock, all my time-stamps are shown as starting in 1970s. Can anyone point me what would be wrong with my JSON format?
Reason I am not using - pointStart and pointInterval: is because sometime pointIntervals can be irregular and hence need to send in the dates.
{
"chart_data": {
"dates": [
1406876400000,
1406876700000,
1406877000000,
1406877300000,
1406877600000,
1406877900000,
1406878200000,
1406878500000,
1406878800000
],
"values": [
{
"data": [
54,
50,
62,
65,
65,
55,
51,
53,
57
]
},
{
"data": [
84,
70,
80,
78,
77,
84,
73,
83,
77
]
}
]
}
}
My Javascript method to display this data is below.
<script type="text/javascript">
$(document).ready(function() {
var chartOptions = {
chart: {
renderTo: 'chart_panel',
type: 'line',
zoomType: 'x'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
title: {text: 'Temperature & Humidity' },
subtitle: {text: 'My-Text' },
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
month: '%e. %b',
day: '%b %e',
hour: '%b %e',
year: '%b'
}
},
yAxis: {
min: 0,
title: {
text: 'Temperature (°F)/Humidity (%)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
series: [{}],
rangeSelector : {
inputEnabled: true,
selected: '0'
},
};
var chartDataUrl = '{% url "chart_data_json" object.id %}';
function loadChart() {
$.getJSON(chartDataUrl,
function(data) {
var seriesOptions = [];
var obj1 = {};
var obj2 = {};
avgByDayOptions.xAxis.categories = data['chart_data']['dates'];
obj1.name = "Temperature";
obj1.data = data['chart_data']['values'][0]['data'];
obj2.data = data['chart_data']['values'][1]['data'];
obj2.name = "Humidity";
seriesOptions[0] = obj1;
seriesOptions[1] = obj2;
chartOptions.series = seriesOptions;
var chart = new Highcharts.StockChart( chartOptions,
function(chart){
// apply the date pickers
setTimeout(function(){
$('input.highcharts-range-selector', $('#'+chart.options.chart.renderTo))
.datepicker()
},0)
}
);
Highcharts.setOptions({ global: { useUTC: false } });
});
}
loadChart();
});
It was may bad once I passed the data in following format everything started work as expected. Just posting reply to my own question in case someone runs into similar issue?
{
"chart_data": {
"values": [
{
"data": [
[
1406851200000,
54
],
[
1406851500000,
50
],
[
1406851800000,
62
],
[
1406852100000,
65
],
[
1406852400000,
65
],
[
1406852700000,
55
],
[
1406853000000,
51
],
[
1406853300000,
53
],
[
1406853600000,
57
]
]
},
{
"data": [
[
1406851200000,
84
],
[
1406851500000,
70
],
[
1406851800000,
80
],
[
1406852100000,
78
],
[
1406852400000,
77
],
[
1406852700000,
84
],
[
1406853000000,
73
],
[
1406853300000,
83
],
[
1406853600000,
77
]
]
}
]
}
}

Resources