Highcharts not displaying in Firefox - javascript

I am using the following JavaScript Code to create a Highchart from a local csv file. This works correctly in Safari and Chrome (need to enable --allow-file-access-from-files for it to work in Chrome), however it does not work for Firefox for some reason. I have tried changing the value of security.fileurl.strict_origin_policy to false but that doesn't change the error or display the charts.
I get a JS "syntax error" for the csv file for ':1:1' which I assume is line 1 column 1. I don't understand why it works for 2 browsers and not for Firefox. I imagine it is something similar to Chrome where I have to enable access to local files but besides changing the about:config I'm not sure how to achieve this.
Any explanations or suggestions are appreciated.
$.get(data, function(csv) {
$('#container').highcharts({
chart: {
zoomType: 'x',
type: 'column',
},
data: {
csv: csv,
lineDelimiter: "\n",
},
title: {
text: 'CSV file data'
},
yAxis: {
title: {
text: 'Bytes'
}
}
});
});

It turns out that adding "text" after $.get(data, function(csv) {} solves this issue for firefox. Not entirely sure why. It takes longer than Chrome or Safari to load but it does load successfully.
Provided you have enabled --allow-file-access-from-files it will work in Chrome and doesn't cause any changes in Safari.
$.get(data, function(csv) {
$('#container').highcharts({
chart: {
zoomType: 'x',
type: 'column',
},
data: {
csv: csv,
lineDelimiter: "\n",
},
title: {
text: 'CSV file data'
},
yAxis: {
title: {
text: 'Bytes'
}
}
});
}, "text");

Related

Simple Highcharts chart not working in Firefox

I am experiencing a strange issue with highcharts and Firefox. For some reason, this code works with Chrome, but not with Firefox:
var options = {
chart: {
renderTo: 'visits',
backgroundColor:null,
type: 'line'
},
exporting: { enabled: false },
title: {
text: 'Visits'
},
xAxis: {
categories: [],
tickInterval: 7,
labels: {
style: {
fontSize:'8px'
}}
},
yAxis: {
labels: {
enabled: false
},
title: {
text: null
}
},
tooltip: {
pointFormat: '{point.y:.0f} Visits'
},
legend: {
enabled: false
},
series: [{
name: [],
data: []
}]};
$.get('downloads/myfile.csv', function(data) {
// Split the lines
var lines = data.split('\n');
$.each(lines, function(lineNo, line) {
var items = line.split(',');
if (lineNo !== 0) {
options.series[0].data.push({
name: items[0],
y: parseFloat(items[1])
});
options.xAxis.categories.push(x);
}
});
var chart = new Highcharts.Chart(options); });
My CSV file has the following data:
2017-09-01,65
2017-09-02,36
2017-09-03,36
2017-09-04,91
2017-09-05,75
2017-09-06,120
Since items[1] is number, why it cannot be displayed in Firefox? If I replace items[1] with a plain number, say "1", I get a flat line which means that for some reason the parseFloat fails. I get no errors or warnings in the console.
How can I deal with this?
I have found why it did not work in firefox. The encoding of the CSV file is UTF-8 with BOM! For some reason Firefox cannot parse it. I have saved the CSV as ANSI and it works as expected. I guess I could resolve this by reading the file with AJAX.

Highcharts not "graphing" in Firefox or Safari

I'm having an odd problem where my Highcharts graph is only properly "graphing" on Chrome. The graph frame itself shows up just fine (the axis' names, labels, white background, etc), but the actual columns do not get animated, nor do they show up on the graph to represent the actual data. It just appears to look like an empty graph.
The data is being called via AJAX. Everything on that end is fine. The code itself is also very simple, so not sure what could be causing this. Here is the code, any help would be greatly appreciated:
Highcharts.chart('modal-graph-wrapper', {
chart: {
type: 'column'
},
title: {
text: 'Build Time vs. Step'
},
yAxis: {
title: {
text: 'Length of Time (seconds)'
},
categories: timeArray
},
xAxis: {
categories: nameArray
},
plotOptions: {
series: {
pointStart: 0
}
},
series: [{
name: 'Build Time (seconds)',
data: timeArray,
lineWidth: 3,
marker: {
radius: 3,
fillColor: '#337ab7'
}
}]
});
I ended up figuring it out. It is because the Date.parse function does not work as expected in Firefox or Safari; whereas in Chrome it works as anticipated. Restructuring the time format solved my issue. Thanks!

Highstock giving error 15

I added two time series in highstock , but after running the sample , I get this error : Highcharts error #15 in console also browser does not show properly.I checked for this error but time series data is in ascending order only, so could not make out why this error coming up ?
$('#chartdiv').highcharts('StockChart', {
rangeSelector: {
selected: 2
},
legend: {
enabled: true
},
credits: {
enabled: false
},
chart: {
zoomType: 'x'
},
title: {
text: 'test highchart'
},
series: seriesOptions
});
Here is the fiddle for above issue.
Your timeArr array isn't sorted actually. Just adding this line gets rid of the error:
timeArr.sort();
See your updated JSFiddle here.

Setting options.rangeSelector.selected to 0 does not set zoom to correct level in highstock

I am trying to change the default zoom level on a simple highstock chart. I've been looking around for a solution and came up with this:
rangeSelector: {
selected:0,
},
This did not work with the code below
chart = new Highcharts.StockChart({
chart: {
renderTo: 'dummycontainer'
},
rangeSelector: {
selected:0,
},
credits: {
enabled: false
},
yAxis: {
title: {
text: ''
},
max: 100
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> <br/>', //({point.change}%)
valueDecimals: 2
},
series: [{
name: 'MMP',
data: [
],
marker : {
enabled : true,
radius : 3
},
shadow : true
}]
});
What could be causing this?
rangeSelector: {
selected:0
}
very much works
Change default time range | Highchart & Highstock # jsFiddle
Check for any other javascript related errors in your browser's javascript console. If you are trying out on IE or even otherwise I would recommend removing the trailing comman(,) from selected:0, like in the code above or the demo.
Trailing commas lead to invalid json and some browsers may not behave correctly with them. You can validate your json # http://jsonlint.com/ or try the JSLint option in jsFiddle.

HighCharts.js is not rendering chart under IE8

I am using HighCharts together with Python to dynamically create charts. All works fine, however I get cannot read property "0" of undefined exception under IE8. Unfortunetly my client want it to work under IE8 as well. So heres the code of the main function:
function generateChart(series) {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'company_chart',
},
xAxis: {
type: "datetime",
},
yAxis: [{
title: {
text: "T1",
},
},{
title: {
text: "T2",
},
},
opposite: true,
}],
plotOptions: {
series: { shadow: false },
column: { shadow: false, },
},
series: series
});
);
Now my ajax request returns some data and I store it in the variable like this:
chart_data = [
{
type: "spline",
color: '#ff0000',
yAxis: 0,
data: dataT1,
},
{
type: "column",
color: '#0000ff',
yAxis: 1,
data: dataT2,
}
];
After that I call generateChart(chart_data);. The format of variables dataT1 and dataT2 is fine, since it works under every other browser. For example dataT1 may look like this:
dataT1 = [ [1325721600000,1.64],
[1325635200000,1.64],
[1325548800000,1.7],
[1325462400000,1.7],];
But still the exception is thrown under IE8. Any ideas how to fix this?
Those dangling commas are causing errors in Internet Explorer. Get rid of them.
Here's an example:
chart: {
renderTo: 'company_chart', // <--- get rid of that comma
},
Internet Explorer considers a comma at the end of an object literal like that to be an error. You should in fact be seeing the "Errors on page" warning, but the error is usually something that does not indicate this actual root cause.
edit — well apparently IE8 is not picky about that, though IE7 is.
edit again — However, IE8 interprets that last dangling comma in your data arrays as meaning that there should be an extra element! In other words:
[1, 2, 3,].length
is 3 in Firefox/Chrome/Safari but it's 4 in Internet Explorer. When you try to access that element, the browser gives you undefined.

Categories

Resources