Highcharts error #13 unless I run under IE compatibility view? - highcharts

I am developing an asp applicaiton which uses WCF service (.svc not .asmx) to send JSON data to highcharts. It only seems to work if I use ie compatibility view. If I don't I get the message:
Microsoft JScript runtime error: Highcharts error #13: http://www.highcharts.com/errors/13
Error number 13 along with online searching suggests I don't have the proper renter to DIV, but it is present. Any ideas what I can to to make my application work in non-compatibility view?
Thanks!
As requested here is some code. I have two charts placed side by side one deals with "Low" turnover items the other with high. Here is the low item chart thus it renders to a named containerLow.
var lowchart = new Highcharts.Chart({
chart: {
renderTo: 'containerLow'
},
xAxis: {
},
plotOptions: {
series: {
cursor: 'pointer',
point: {
events: {
click: function () {
//ChartClicked(this.x, this.y, this, this.series.name, this.series.color, this.index);
ChartClicked(this, 'Low');
}
}
}
}
},
tooltip: {
formatter: function () {
var txt = "$= <b>" + this.point.x + "</b><br/>"
+ "Wait = <b>" + this.point.y + "</b><br/>"
+ "Other DB Info for future Bow Wave, etc. <b><br/>"
+ "Avg Fill Rate = <b>" + this.point.config.averageFillRate + "</b><br/>"
+ "Average On Hand = <b>" + this.point.config.averageOnHand + "</b><br/>"
+ "Average Workload = <b>" + this.point.config.averageWorkload + "</b><br/>"
return txt;
}
}
}); //end chart
My web service get a JSON string with multiple series in it. On page load I call the web service (twice once for hight and low items) and loop through the series array to plot the multiple curves.
function pageLoad() {
JSONGraphing.GetDataDB(getParameterByName("id"), 2, OnGetDataCompleteLow, OnError);
JSONGraphing.GetDataDB(getParameterByName("id"), 1, OnGetDataCompleteHigh, OnError);
}
Here is an example of one of the call back functions for the low graph.
function OnGetDataCompleteLow(result) {
var webServiceData = eval("(" + result + ")");
for (var i = 0; i < webServiceData.series.length; i++) {
lowchart.addSeries({
data: webServiceData.series[i].data
});
}
lowchart.yAxis[0].setTitle({
text: 'Wait time in Days'
});
lowchart.xAxis[0].setTitle({
text: 'Investment in Dollars'
});
lowchart.setTitle({ text: 'Low Frequency Items' });
}
I am in a bit of a time crunch any and all help greatly appreciated.

To make sure that the container exists you have to run your code after it gets rendered, it can be done by the following ways.
document.ready(function() {
// your code
});
or
<div id="container"> </div>
<script type="type="text/javascript"">
// your code here
</script>
or
(function() {
// your code here
})

Related

JqueryUI autocomplete remove results minLength

I have a problem with jqueryui autocomplete.
I print out the results of the autocomplete in another div like this
$(function () {
var ac = $("#search").autocomplete({
source: "myurl",
search: function (event, ui) {
// clear the existing result set
$('#results').empty();
},
minLength: 3
});
ac.data('ui-autocomplete')._renderItem = function (ul, item) {
return $('<div class="col-md-2">' +
'<div class="thumbail">' +
'' +
'</div>' +
'</div>')
.appendTo($('#results'));
};
});
This works great when I search for something with over 2 characters. But if I press backspace and erase one character, making the query less than minLength, the search method is not called anymore, meaning that the previous results stay in my results div. Is there a way to clear the results when the query is shorter than minLength?
Try binding an event handler like:
$("#search").on('input', function() {
if ($(this).val().length >= 3) return;
$('#results').empty();
});

OpenLayers WFS request on mouseclick to GeoServer doesn't load features into vector layer

I would appreciate advice on getting an OpenLayers WFS request to GeoServer working in OL3.2 or later, triggered by a mouse singleclick.
By way of background, I have had this working fine for a year at http://maps.nls.uk/geo/find/ using OL 3.1. However, Firefox version 43.0 records the mouse click event at the top left corner of the map canvas, not on the real pixel location clicked on - earlier versions of Firefox, Chrome and IE record the correct pixel location on the canvas. From my basic tests, later versions of OL after 3.1 record the correct pixel location using Firefox 43.0, so I would like to upgrade to a newer version of OL.
My original code in OL3.1 is as follows:
var urlgeoserver = 'http://geoserver2.nls.uk/geoserver/wfs?service=WFS' +
'&version=1.1.0&request=GetFeature&typename=' + TypeName +
'&outputFormat=text/javascript&format_options=callback:loadFeatures' +
'&srsname=EPSG:3857&cql_filter=INTERSECTS(the_geom,POINT('
+ point27700[0] + ' ' + point27700[1] + '))';
}
var vectorSource = new ol.source.ServerVector({
format: new ol.format.GeoJSON(),
loader: function(extent, resolution, projection) {
var url = urlgeoserver
$.ajax({
url: url,
dataType: 'jsonp',
jsonpCallback: 'loadFeatures',
success: handleJson
});
},
strategy: ol.loadingstrategy.createTile(new ol.tilegrid.XYZ({
maxZoom: 19
})),
projection: 'EPSG:3857'
});
function handleJson(data) {
vectorSource.addFeatures(vectorSource.readFeatures(data));
....
I have tried adapting this following the example at http://openlayers.org/en/v3.6.0/examples/vector-wfs.html and OL 3.6 with the code below:
var urlgeoserver = 'http://geoserver2.nls.uk/geoserver/wfs?service=WFS' +
'&version=1.1.0&request=GetFeature&typename=' + TypeName +
'&outputFormat=text/javascript&format_options=callback:loadFeatures' +
'&srsname=EPSG:3857&cql_filter=INTERSECTS(the_geom,POINT('
+ point27700[0] + ' ' + point27700[1] + '))';
}
vectorSource = new ol.source.Vector({
loader: function(extent, resolution, projection) {
var url = urlgeoserver
// use jsonp: false to prevent jQuery from adding the "callback"
// parameter to the URL
$.ajax({url: url, dataType: 'jsonp'});
},
strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
maxZoom: 19
}))
});
window.loadFeatures(response) {
vectorSource.addFeatures(geojsonFormat.readFeatures(response));
};
However I try things, it fails to retrieve features from GeoServer into vectorSource and I would appreciate any pointers or suggestions.
Many thanks,
Just in case helpful for others, following further investigation, I realised I just needed to add a 'jsonp: false' to the $.ajax query for it to work. The correct vectorSource syntax is therefore:
var geojsonFormat = new ol.format.GeoJSON();
var vectorSource = new ol.source.Vector({
loader: function(extent, resolution, projection) {
var url = urlgeoserver
$.ajax({url: url, dataType: 'jsonp', jsonp: false})
},
strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
maxZoom: 19
}))
});
window.loadFeatures = function(response) {
vectorSource.addFeatures(geojsonFormat.readFeatures(response));
};
This is implemented at: http://maps.nls.uk/geo/find/

How to show specific point to show specific information in HighCharts

I am new to highcharts and I am working on a cricket app in which I have to display Run rate per over and number of wickets in an over. If there is a wicket(s) in the specific over I want to show a ball(s) to the point and on hover or click to that point it show the information about player and bowler etc.
What I want is you can view from this Link Crichq Graphs
I want the same think like in crichq graphs, but don't know how to do.
Please help me out of this issue.
You can use the point marker settings to indicate where the wickets fell. e.g. make it a different colour and size. http://api.highcharts.com/highcharts#series.data.marker
I would process the data as follows:
var ausData = [ { x:1, y:1 },
{ x:2, y:24, out:{num:2,names:['john','doe']} },
{ x:3, y:5 },
{ x:4, y:8 },
{ x:5, y:22 },
{ x:6, y:11 } ];
for (var p in ausData) {
var point = ausData[p];
if (point.out !== undefined) {
point.marker = {fillColor:'red',radius:4*point.out.num};
} else {
point.marker = {radius:5};
}
}
This start with the basic info, and then adds custom point markers depending on how the wickets fill.
The only other thing to do is customise the tooltip to give the names e.g.:
tooltip: {
formatter: function () {
var text = 'Over: ' + this.x +
' Runs: ' + this.y;
if (this.point.out !== undefined) {
text = text + '<br>Out: ' + this.point.out.num;
for (var n in this.point.out.names) {
text = text + ' ' + this.point.out.names[n];
}
}
return text;
}
},
http://jsfiddle.net/d6fgwg14/

Highcharts Chart inside of a Highslide popout

I am currently trying to put a Highcharts chart inside of a Highslide pop-out (the Highslide pop-out itself comes out of an existing Highcharts line graph). Basically, I want someone to be able to click on a point in the line graph and have a Highslides popout that contains additional charts with further information on that data point.
The code below works - once. After the user clicks on a point and then closes the Highslide popout, the Highcharts graphs no longer show up in the Highslide popout if you click on the point again (the data contained in the "tile" div does continue to appear, however).
What's happening here? Why do the charts only show up when you first click on the point but not on any subsequent clicks?
PS: If there are multiple points in the line graph, clicking on each point once will correctly show the additional charts for that data point. But if you close the Highslide popout and click on the point again, it will not show the Highcharts graphs.
Note: The two functions in the .done call create the Highcharts graphs for the Highslide pop-out
Code (inside series for the existing Highcharts line graph):
click: function ()
{
window.Task_ID = this.Task_ID;
window.Task_Record = this.Task_Record;
hs.htmlExpand(null,
{
pageOrigin:
{
x: this.pageX,
y: this.pageY
},
headingText: "<p style='margin: 0 auto;'> Task: " + this.Task_ID + " for " + this.Company + "</p>",
maincontentText: "<p class='tile'></p>" + "<div class='charts'><p class = 'studentTaskChart' id='studentTaskChart" + this.Task_ID + "'></p>" + "<p class = 'businessTaskChart' id='businessTaskChart" + this.Task_ID + "'></p></div>",
width: 700,
height: 700
}),
hs.Expander.prototype.onAfterExpand(null, {
maincontentText:
$.ajax
({
type: "post",
url: "TrackRecord_Beta/practice.php",
data:
{
"timestamp" : this.x
},
success: function(result)
{
$('.tile').html(result);
}
})
.done(function()
{
createStudentTaskChart();
createBusinessTaskChart();
}),
})
}
The problem is that Highslide each time creates new window (that's why you can have more than one), so you need to change each time container's ID (not create duplicates). For example: http://jsfiddle.net/y4JV5/4/
I know, this is not using AJAX, but idea should be the same:
var counter = 0;
hs.Expander.prototype.onAfterExpand = addChart;
function addChart() {
var chart = $("#hc-test" + counter).highcharts();
if (chart) {
chart.destroy();
}
$("#hc-test" + counter).highcharts({
chart: {
width: 300,
height: 300
},
series: [{
type: 'pie',
data: [Math.random() * 10, Math.random() * 10, Math.random() * 10]
}]
});
}
Click handler:
click: function () {
counter++;
hs.htmlExpand(null, {
pageOrigin: {
x: this.pageX,
y: this.pageY
},
headingText: this.series.name,
maincontentText: '<div>' + Highcharts.dateFormat('%A, %b %e, %Y', this.x) + ':<br/> ' + this.y + ' visits' + '</div><div id="hc-test' + counter + '"></div>',
width: 310,
height: 500
});
}

Duplicate Series in the legend when exporting

Sorry if this question has been asked before but I could not find a similar question that is related to my problem.
The issue I am experiencing is that when exporting to PNG, JPG etc. the series would double up. So if my on screen chart has four series plotted, when it comes to exporting it will have eight series in the legend.
I think the problem is related to 'load' event of the chart is being executed subsequent times when exporting.
$(function () {
Highcharts.setOptions({
global: {
useUTC: false
}
});
function fnFetchData(chart) {
// Just imagine an AJAX request has just been done to get a JSON response
// JSONData = $.getJSON('/FetchSales');
var JSONData
JSONData = {
seriesName: 'Sales 2013',
data: [(Math.random() * 100) + 1, (Math.random() * 100) + 1,
(Math.random() * 100) + 1, (Math.random() * 100) + 1,
(Math.random() * 100) + 1, (Math.random() * 100) + 1,
(Math.random() * 100) + 1, (Math.random() * 100) + 1,
(Math.random() * 100) + 1, (Math.random() * 100) + 1,
(Math.random() * 100) + 1, (Math.random() * 100) + 1,
(Math.random() * 100) + 1]
};
//alert('About to load the chart Data');
chart.addSeries({
name: JSONData.seriesName,
data: JSONData.data,
type: 'spline'
}, true);
chart.redraw(true);
};
// Create the chart
$('#container').highcharts({
chart: {
events: {
load: function () {
fnFetchData(this);
}
}
},
title: {
text: 'Chart Data from load Event'
},
exporting: {
enabled: true,
scale: 2,
filename: 'ChartWithDoubleupSeries'
},
spline: {
animation: false
},
series: []
});
});
I can reproduce the issue, here is an example:
http://jsfiddle.net/FtjJF/
I keep thinking it might be a bug that the 'load' event is being executed when exporting unless this is the standard behaviour and I need to include and extra option.
Versions details:
Highstock JS v1.3.1 (2013-04-09)
Highstock JS v1.3.1 (2013-04-09) Exporting module
Export chart through pragmatically like , make load event null
var chart = $('#chart-container').highcharts();
chart.exportChart(
{type: 'image/png', filename: 'name'},
{chart: { events:null } });
Simple workaround is to use setTimeout():
load: function () {
var chart = this;
setTimeout(function() {
fnFetchData(chart);
}, 1);
}
And for me looks like a bug, reported: https://github.com/highslide-software/highcharts.com/issues/1868
Thanks!
Currently as an alternative solution was to store the series names into an array. When the load event is fired I check the series name to see if it exists in the array. If it does, don't call the addSeries method.
var AvailableSeries = [];
$( chart.series).each(function(key,value){
AvailableSeries.push(value.name);
});
if ($.inArray( 'Sales 2013' ,AvailableSeries)==-1 ) {
chart.addSeries(name:'Sales 2013', data:[234,453,56732,435,4,45,32,232,43]});
};
After a little bit more investigation for a long term solution, I've added this line "options.chart.events = null;" to the exportpting.js script.
The problem with this solution might be a legitimate reason for the chart's events to be executed when the chart is being exported. I can't think of one. May be there should be an option to suppress events when exporting:
{ exporting:{ skipEvents:true } }

Resources