Responsive Line Chart using High Charts & Bootstrap 3 - html

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

Related

How to add space between xAxis line itself and the bottom edge of the bar on Apache Echarts

Here is a design pic for reference, note the 2px of space. The axisLine > lineStyle doesn't offer a padding property. Any suggestions? Chart design example
As I know this is not possible by default but you can try to simulate this option. Something like that:
var myChart = echarts.init(document.getElementById('chart'));
var option = {
tooltip: {},
xAxis: [{
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
axisLine: {
lineStyle: {
width: 1,
color: 'white',
shadowColor: 'black',
shadowOffsetY: 2
}
},
axisLabel: {
color: 'black'
},
axisTick: {
lineStyle: {
color: 'black'
}
}
}],
yAxis: [{
type: 'value',
}],
series: [{
type: 'bar',
data: [1, 34, 12, 23, 43, 64, 45]
}]
};
myChart.setOption(option);
<script src="https://cdn.jsdelivr.net/npm/echarts#5.2.2/dist/echarts.min.js"></script>
<div id="chart" style="width: 600px;height:400px;"></div>

Apex charts in Angular 9

I have some problem using apex charts in angular 9, essentially I'm able to see the chart (line chart) when I mock the data as in the first screenshot, but I can't get data from REST API, I mean the chart disappears.
mocked datas
This is the method containing the chart:
drawGraph(){
this.projectService.getLineChartData(this.getID()).then((data) =>{
for(let i = 0; i<data.resourceListSize; i++){
this.chartOptions = {
series: [
{
name: "data",
data: [28, 29, 33, 36, 32, 32, 33]
},
{
name: "Low - 2013",
data: [12, 11, 14, 18, 17, 13, 13]
}
],
chart: {
height: 350,
type: "line",
dropShadow: {
enabled: true,
color: "#000",
top: 18,
left: 7,
blur: 10,
opacity: 0.2
},
toolbar: {
show: false
}
},
colors: ["#77B6EA", "#545454"],
dataLabels: {
enabled: true
},
stroke: {
curve: "smooth"
},
title: {
text: "Average High & Low Temperature",
align: "left"
},
grid: {
borderColor: "#e7e7e7",
row: {
colors: ["#f3f3f3", "transparent"], // takes an array which will be repeated on columns
opacity: 0.5
}
},
markers: {
size: 1
},
xaxis: {
categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul"],
title: {
text: "Month"
}
},
yaxis: {
title: {
text: "Temperature"
},
min: 5,
max: 40
},
legend: {
position: "top",
horizontalAlign: "right",
floating: true,
offsetY: -25,
offsetX: -5
}
};
}
})
}
Any help would be appreciated! Thank you
Step 1,
set the configuration with out data like below(minimum configuration)
this.chartOptions = {
series: [],
chart: {
height: 350,
type: "line"
},
xaxis: {}
}
Step 2:
Data from api response and set to "chartoptions" variable,
this.chartOptions.series=[{
name: "data",
data: [28, 29, 33, 36, 32, 32, 33]
}, {
name: "Low - 2013",
data: [12, 11, 14, 18, 17, 13, 13]
}
];
this.chartOptions.xaxis=
{
categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul"]
}

JS - Defining display sencha window function

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();
}

populating x-axis(Category) Highcharts ajax

I need assistance on how to dynamically bind my x-axis. I have written a webservice, that will fetch the data from the stored procedure.
I am stuck on displaying just the first column from the SP as for the x-axis.
$.ajax({
type: "POST",
url: "/path/path.asmx/xpath",
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function(data) {
alert("X_axis function is being hit")
// Parse JSON data:
var jsonCategories = eval('(' + data + ')');
alert(jsonCategories);
// Pass parsed data to the chart:
$('#Div3').xAxis[0].setCategories(jsonCategories);
}
})
// };
$('#Div3').highcharts({
chart: {
type: 'areaspline',
backgroundColor: {
linearGradient: { x1: 0, y1: 0, x2: 1, y2: 1 },
stops: [
[0, '#2a2a2b'],
[1, '#3e3e40']
]
}
},
title: {
text: 'Average Disc Space consumption',
style: { fontSize: 10, color: '#E0E0E3' }
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: 0,
y: 0,
floating: true,
borderWidth: 1,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#EEE'
},
legend: {
enabled: true
},
xAxis: {
categories: [],
labels: {
style: {
color: '#E0E0E3'
}
},
plotBands: [{
from: 4.5,
to: 6.5,
color: 'rgba(68, 170, 213, .2)'
}]
},
yAxis: {
title: {
text: 'Disc (GB)',
style: { fontSize: 10, color: '#E0E0E3' }
},
labels: {
style: {
color: '#E0E0E3'
}
}
},
tooltip: {
shared: true,
valueSuffix: ' GB'
},
credits: {
enabled: false
},
plotOptions: {
areaspline: {
fillOpacity: 0.5
}
},
series: [{
name: 'DB size',
data: [20, 10, 65, 3, 55, 62, 58]
}, {
name: 'Data size',
data: [19, 34, 47, 31, 3, 54, 41]
},
{
name: 'Log size',
data: [11, 34, 49, 38, 38, 80, 10]
},
{
name: 'Backup size',
data: [1, 32, 47, 3, 39, 59, 4]
}
]
});

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'
}
}
}]
});
});