t.substring is not a function in ApexCharts - javascript

Porridge everyone, I got a bug in ApexCharts. Who knows what this is wrong? Thanks!
My Code:
// Option Chart
var options = {
series:
[
{
name: 'Operating',
data: [1785, 1661, 1663, 1653, 1882, 1725, 6153, 1153, 6153, 6153, 6153, 1653, 1153, 1663, 1661]
}, {
name: 'Stopping',
data: [4072, 0, 0, 0, 248, 2534, 8533, 0, 0, 0, 0, 0, 0, 0, 0]
}, {
name: 'Error',
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
},{
name: 'No Sign',
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
}
],
chart: {
type: 'bar',
height: heightChart,
stacked: true,
stackType: '100%'
},
responsive: [{
breakpoint: 480,
options: {
legend: {
position: 'bottom',
offsetX: -10,
offsetY: 0
}
}
}],
xaxis: {
labels: {
style: {
colors: [],
fontSize: '15px',
fontFamily: 'Helvetica, Arial, sans-serif',
fontWeight: 400,
cssClass: 'apexcharts-xaxis-label',
}
},
},
yaxis: {
labels: {
style: {
colors: [],
fontSize: '15px',
fontFamily: 'Helvetica, Arial, sans-serif',
fontWeight: 400,
cssClass: 'apexcharts-xaxis-label',
}
},
},
};
var chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();
This Is Error:
I tried to find out about this error, mostly due to data errors. But my data is right. When we replace 0 to 1 this error disappears.
And after creating the plot option, the graph generated an error:
plotOptions: {
bar: {
columnWidth: '60%',
colors: {
ranges: [{
from: 0,
to: 0,
color: ['#0000']
}],
backgroundBarColors: [],
backgroundBarOpacity: 1,
backgroundBarRadius: 0,
},
}
},

Your code runs fine (produces the result as shown below) and generates no errors on my side.
Can you check which version of ApexCharts are you using?

Related

chart.js cuts data points to half

I have a chart showing website calls the last 7 days. There it is:
Here is the initialization:
varwebsitecalls_chart = new Chart(websitecalls_chartel, {
type: 'line',
data: {
labels: ["Sa", "So", "Mo", "Di", "Mi", "Do", "Fr"],
datasets: [{
label: 'Websitecalls',
data: [0, 0, 0, 0, 0, 0, 0],
borderWidth: 2,
borderColor: '#00000',
backgroundColor: '#ffff',
pointStyle: 'circle',
pointRadius: 7,
cubicInterpolationMode: 'monotone',
tension: 0.4,
}]
},
options: {
responsive: true,
plugins: {
legend: {
display: false
},
},
scales: {
x: {
grid: {
display: false,
}
},
y: {
min: 0,
ticks: {
precision: 0,
font: {
family: 'Montserrat',
},
},
grid: {
borderDash: [5, 5],
}
},
}
},
});
Problem:
The Problem is that the chart cuts of the circles when the data is 0 because I set min to 0. I have to set min to 0 because negative websitecalls can not exist. If I do not set it -1 will be displayed. Is there a way to fix this designtechnical issue?
Thanks in advance,
Filip.
No idea why, but defining y.beginAtZero: true instead of y.min: 0 will solve the problem.
Please take a look at your amended and runnable code and see how it works.
new Chart('websitecalls_chartel', {
type: 'line',
data: {
labels: ["Sa", "So", "Mo", "Di", "Mi", "Do", "Fr"],
datasets: [{
label: 'Websitecalls',
data: [0, 0, 0, 0, 0, 0, 0],
borderWidth: 2,
borderColor: '#00000',
backgroundColor: '#ffff',
pointStyle: 'circle',
pointRadius: 7,
cubicInterpolationMode: 'monotone',
tension: 0.4,
}]
},
options: {
responsive: true,
plugins: {
legend: {
display: false
},
},
scales: {
x: {
grid: {
display: false,
}
},
y: {
beginAtZero: true,
ticks: {
precision: 0,
font: {
family: 'Montserrat',
},
},
grid: {
borderDash: [5, 5],
}
},
}
},
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.7.1/chart.js"></script>
<canvas id="websitecalls_chartel" height="80"></canvas>
Chart.js documentation states...
beginAtZero: if true, scale will include 0 if it is not already included.
min: user defined minimum number for the scale, overrides minimum value from data.

highcharts-ng, gauge that can handle negative values

I am using ng-highcharts and I'm trying to create a gauge that can handle negative values, I have almost got there. However, I want zero to be at the top (in others words, I want the chart to be rotated 90 degrees to the right), and for some reason, the -200 value is printed twice/overlapping. What am I missing/doing wrong?
http://jsfiddle.net/Hjdnw/2006/
this is what it should ideally look like, but I want the same thing in ng-highcharts so I can use in my angular application
http://jsfiddle.net/5rncm2nn/1/
I tried creating my own directive instead of using ng-highcharts,and its working as expected for me.
Also remove the options object which is wrapping the chart object in your config, that might also be creating problem
Use this config
{
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: -200,
max: 200,
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: 200,
color: '#55BF3B' // green
}, { from: -200,
to: 0,
color: '#DF5353' // red
}]
},
series: [{
name: 'Speed',
data: [80],
tooltip: {
valueSuffix: ' km/h'
}
}]
}
Same as yours just removed the options object
Checkout this fiddle
http://jsfiddle.net/Hjdnw/2010/

Change the style of Highchart stacked colum chart

I plot a stacked column Highchart. The chart is working fine but there is some style issues. The Y-axis names are showing above the chart so the subtitle is not showing I need to show the Y-axis names below.How can I change this?Thanks in advance for help...
Here is my code
<script type="text/javascript">
$(function () {
$('#chart_div').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Material Vs Subcategory'
},
subtitle: {
text: 'Source: www.test.com'
},
xAxis: {
categories: ['Air Filtration','Clothing','Sporting Goods','Home Furnishings','Paint','Storage','Toys and Games']
},
yAxis: {
min: 0,
title: {
text: 'Number of Products'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
legend: {
align: 'right',
x: -70,
verticalAlign: 'top',
y: 20,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
formatter: function () {
return '<b>' + this.x + '</b><br/>' +
this.series.name + ': ' + this.y + '<br/>' +
'Total: ' + this.point.stackTotal;
}
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: false,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: [{
name: 'Unclassifiable',
data: [0, 1, 0, 0, 1, 0, 0]
},{
name: 'Aluminium',
data: [0, 0, 0, 0, 0, 0, 0]
},{
name: 'Calcium',
data: [0, 0, 0, 1, 0, 0, 0]
},{
name: 'Copper',
data: [0, 0, 0, 0, 0, 0, 0]
},{
name: 'Gold',
data: [0, 1, 0, 0, 1, 1, 0]
},{
name: 'Iron',
data: [0, 0, 0, 0, 0, 0, 0]
},{
name: 'Platinum',
data: [0, 0, 0, 0, 1, 0, 1]
},{
name: 'Silver',
data: [0, 3, 3, 0, 0, 0, 0]
},{
name: 'Steel',
data: [1, 0, 0, 1, 0, 0, 0]
},{
name: 'Unknown',
data: [0, 1, 0, 0, 1, 0, 0]
}]
});
});
</script>
Taking out the "Floating" and x/y positions makes it look a little cleaner too:
legend: {
verticalAlign: 'bottom',
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
http://jsfiddle.net/38Mkf/1/
Is that you want verticalAlign: bottom on legend part?
legend: {
align: 'right',
x: -70,
verticalAlign: 'bottom',
y: 20,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
http://jsfiddle.net/38Mkf/

How do I pass jquery result to highchart

Absolute novice here at JavaScript so please forgive any bad coding.
I have been working on a project using Highchart and wish to read the value of a file (actually read the file into an array and grab a specific value - I will use other values for other graphs).
With the help of others here I can now display the value of the array into HTML however I cannot pass this into the Highchart.
My prototype page (so you can see the output) can be found at
http://maccas.chickenkiller.com/1.html
The code is
<html debug="false">
<head>
<title>Adam's hacked up demo</title>
<META HTTP-EQUIV="refresh" CONTENT="300">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/highcharts-more.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
</head>
<script>
jQuery(function($){ // encapsulate jQuery
$.ajax(
{
url:'livedata.txt',
async:false,
success: function(data){
livedata = data.split(',');
}
});
function drawGraph(phvalue) {
var phvalue=livedata[3];
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'gauge',
plotBackgroundColor: null,
plotBackgroundImage: null,
plotBorderWidth: 0,
plotShadow: false
},
title: {
text: 'live pH'
},
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: 8,
max: 9,
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'
},
plotBands: [{
from: 8,
to: 8.3,
color: '#55BF3B' // green
}, {
from: 8.3,
to: 8.7,
color: '#DDDF0D' // yellow
}, {
from: 8.7,
to: 9,
color: '#DF5353' // red
}]
},
series: [{
name: 'Current pH',
data: [phvalue],
tooltip: {
valueSuffix: ' pH'
}
}]
});
}
$(document).ready(function () {
drawGraph();
});
});
</script>
<body>
<table>
<tr>
<td><div id="container" style="width:90%; height:400px;"></div></td>
</tr>
</table>
</body>
</html>
Does anyone have an idea how to get the var phvalue to display in Highcharts?
Thanks in advance.
Since ajax is asynchronous, you can draw the graph once the request is complete
jQuery(function($){ // encapsulate jQuery
$.ajax(
{
url:'livedata.txt',
async:false,
success: function(data){
livedata = data.split(',');
highcharts(livedata[3])
}
});
function highcharts (phvalue) {
$('#realtimeph').highcharts({
chart: {
type: 'gauge',
plotBackgroundColor: null,
plotBackgroundImage: null,
plotBorderWidth: 0,
plotShadow: false
},
title: {
text: 'live pH'
},
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: 8,
max: 9,
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'
},
plotBands: [{
from: 8,
to: 8.3,
color: '#55BF3B' // green
}, {
from: 8.3,
to: 8.7,
color: '#DDDF0D' // yellow
}, {
from: 8.7,
to: 9,
color: '#DF5353' // red
}]
},
series: [{
name: 'Current pH',
data: [phvalue],
tooltip: {
valueSuffix: ' pH'
}
}]
});
}
});
This was surprisingly complicated. You want:
$('#container').highcharts().series[0].points[0].update(x)
where x is the number you want to update with

Highcharts Gauge

I'm using highcharts and i'd like to show a big gauge(500x500px).
Resizing the gauge was quite easy, but the small block with the value in it doesn't resize. How can I make that small block bigger?
Thanks for the help!
jsFiddle: http://jsfiddle.net/AVd8k/
$(function () {
$('#container').highcharts({
chart: {
type: 'gauge',
plotBackgroundColor: null,
plotBackgroundImage: null,
plotBorderWidth: 0,
plotShadow: false,
width: 500,
height: 500
},
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: 200,
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: [{
name: 'Speed',
data: [80],
tooltip: {
valueSuffix: ' km/h'
}
}]
},
// Add some life
function (chart) {
if (!chart.renderer.forExport) {
setInterval(function () {
var point = chart.series[0].points[0],
newVal,
inc = Math.round((Math.random() - 0.5) * 20);
newVal = point.y + inc;
if (newVal < 0 || newVal > 200) {
newVal = point.y - inc;
}
point.update(newVal);
}, 3000);
}
});
});
try this by replacing series (whole object) with:
series: [{
name: 'Speed',
data: [80],
tooltip: {
valueSuffix: ' km/h'
},
dataLabels: {
enabled: true,
style: {
//fontWeight:'bold',
fontSize: '22px'
}
}
}]
Proof: http://jsfiddle.net/nmQfE/
Of course, you can adjust the font size as you want
It looks like the property you are after is:
plotOptions.gauge.dataLabels.style.fontSize
http://api.highcharts.com/highcharts#plotOptions.gauge.dataLabels.style
Try adding something like this to the options:
plotOptions: {
gauge: {
dataLabels: {
style: {
fontSize: '60px'
}
}
}
}
You may need to reposition it using the x and y properties.

Categories