Changing data to be visualized in jvector Map - jvectormap

I have two types of maps of Nepal (districts map of Nepal and ecological map of Nepal). I have two data sets for each of the above type. I am trying to create a visualization where users can first choose what type of map they want and then later what data they want to be visualized. (using dropdowns).
These are the codes for dropdowns.
<select id="changeMap">
<option>Change Map</option>
<option value="ecoMap">Ecological Region</option>
<option value="world_mill_en">Districts</option>
</select>
<select id="changedata">
<option>Change Data</option>
<option value="Caste 1">CASTE 1</option>
<option value="Caste 2">CASTE 2</option>
</select>
This is the jvector Map function.
<div id="container"></div>
<script>
var vmap = '<div id="vmap" style="width: 600px; height: 400px;"></div>';
$('#changeMap').on('change', function () {
var _map = $(this).val();
$('#vmap').remove();
$('#container').append(vmap);
$('#vmap').vectorMap({
map: _map,
backgroundColor: '#000000',
enableZoom: true,
regionsSelectable : false,
series: {
regions: [{
values: data,
scale: ['#fffad6', '#d05300'],
normalizeFunction: 'polynomial'
}]
}});
});
</script>
Now, how do I make this drop- drop down combination work to visualize?
Thanks!

I guess u want a complete dynamic implementation of the map. I used the same for creating Australia's map with dynamic regions plotted on it on the fly.
Initially create the jvectormap object with path attribute left empty as shown below:
var auJSON = {
"insets": [
{
"width": 900.0,
"top": 0,
"height": 850.8001894248416,
"bbox": [
{
"y": 1125139.6460741498,
"x": 12575140.762771795
},
{
"y": 5412845.645305354,
"x": 17110794.900221862
}],
"left": 0
}
],
"paths": {
},
"height": 850.8001894248416,
"projection":
{
"type": "merc",
"centralMeridian": 0.0
},
"width": 900.0
};
Now, on click on any of the option you have to insert the objects in the path attribute dynamically and finally render the map. I created an array of objects below.
d3.select("#regionSVG").selectAll("path")
.each(function () {
var obj = {
"path": $(this).attr("d"),
"name": $(this).attr("name"),
"id": this.id
}
that.regionPathArray.push(obj);
});
Now i passed on this array to fill in the empty path attribute as below.
initRegionLoading(that.regionPathArray);
function initRegionLoading(arr) {
var initialJSON = auJSON;
for (var i = 0; i < arr.length; i++) {
initialJSON.paths[arr[i].name] = arr[i];
}
$.fn.vectorMap('addMap', 'au_reg_en', initialJSON);
}
And then i displayed the map.
this.ausie_map = new jvm.WorldMap({
map: 'au_reg_en',
container: $('#auMap_' + that.zoomLevel),
});
That solves my problem. Hope it does yours too.

Related

DataTables warning: table id=example - Invalid JSON response while pagination from server

this is my table
<table id="example" class="display" style="width: 100%">
<thead>
<tr>
<th>latitude</th>
<th>longitude</th>
</tr>
</thead>
<tfoot>
<tr>
<th>latitude</th>
<th>longitude</th>
</tr>
</tfoot>
</table>
this is my script
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet" />
<script>
$(document).ready(function () {
$(document).ready(function () {
$('#example').DataTable({
"processing": true,
"serverSide": true,
"info": true,
"stateSave": true,
"lengthMenu": [[10, 20, 50, -1], [10, 20, 50, "All"]],
"ajax": {
"url": "Default3.aspx/GetRouteName",
"type": "GET"
},
"columns": [
{ "data": "latitude" },
{ "data": "longitude" }
],
"order": [[0, "asc"]]
});
});
});
</script>
and at he end of the page i am loading the below script
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
this is my server
[WebMethod]
public static string GetRouteName()
{
List<location> b = new List<location>();
for (int i = 0; i < 1000; i++)
{
location l = new location();
l.latitude = 1233;
l.longitude = 123123;
b.Add(l);
}
bise bb = new bise();
bb.data = b;
bb.draw = 3;
bb.recordsFiltered = 1000;
bb.recordsTotal = 1000;
return JsonConvert.SerializeObject(bb);
}
i keep getting DataTables warning: table id=example - Invalid JSON response i have tried so many turn arounds but same issue,all i need is to be able to paginate the datatable from the server because i have big data,but the ajax call is not even firing, reference this link datatable from server
[WebMethod]
public static string GetRouteName()
{
List<location> b = new List<location>();
for (int i = 0; i < 1000; i++)
{
location l = new location();
l.latitude = 1233;
l.longitude = 123123;
b.Add(l);
}
return JsonConvert.SerializeObject(b);
}
can you try this? is it working?
I'm not familiar with .NET but I would suggest simply doing it this way to respect the desired format (this is server side pseudo code, feel free to translate it to any language you desire) :
function GetRouteName() // returns an object
{
Array b = new Array();
for (int i = 0; i < 1000; i++)
{
Array l = new Array();
l.latitude = 1233;
l.longitude = 123123;
b["data"].Add(l); // Add the longitude/latitude array to a data field of the returned array
}
return JsonConvert.SerializeObject(b); // return the array b after converting it to json
}
Remember, your returned json needs to look like this :
{
"data": [
{
"longitude": "123",
"latitude": "123123"
},
{
"longitude": "123",
"latitude": "123123"
},
{
"longitude": "123",
"latitude": "123123"
}
]
}
It needs to be an object containing data, and inside that multiple objects having as key longitude and latitude with the proper parameters.

Amchart doesn't show up when listed with html <select> tag

My previous issue was to get json data attached to amcharts, after struggling for a while, I got it running the way I want. But when I move it from test page to page where it would be listed with other charts it doesn't seem to work. When I click on blank chart this error appears in the console
Uncaught TypeError: Cannot read property 'length' of undefined
at Object.xToIndex (serial.js:14)
at b.handleCursorMove (serial.js:8)
at Object.a.inherits.b.fire (amcharts.js:1)
at Object.dispatchMovedEvent (amcharts.js:27)
at Object.handleMouseDown (amcharts.js:26)
at b.handleMouseDown (serial.js:1)
at HTMLDivElement.<anonymous> (amcharts.js:18)
Below is the code which is working when I have it on separate page
var chart = AmCharts.makeChart("chart1", {
"type": "serial",
"dataLoader": {
"url": "#myURL"
},
"valueAxes": [{
"title": "Load Average",
"gridColor": "#FFFFFF",
"gridAlpha": 0.2,
"dashLength": 0
}],
"gridAboveGraphs": true,
"startDuration": 1,
"graphs": [{
"balloonText": "[[title]] of [[category]]:[[value]]",
"id": "AmGraph-1",
"lineThickness": 3,
"valueField": "LoadAverage"
}],
"chartCursor": {
"categoryBalloonEnabled": false,
"cursorAlpha": 0,
"zoomable": false
},
"categoryField": "EndTimeLoop",
"categoryAxis": {
"title": "End Time Loop",
"gridPosition": "start",
"gridAlpha": 0,
"tickPosition": "start",
"tickLength": 20,
"labelRotation": 90
}
});
function setDataSet(dataset_url) {
AmCharts.loadFile(dataset_url, {}, function(data) {
chart.dataProvider = AmCharts.parseJSON(data);
chart.validateData();
});
};
this is the part where select happens in html side
<div class="chartWrapper" id="chartSingleTest1">
<select onchange="showChart(this.options[this.selectedIndex].value);">
<option value="chart1">Chart #1</option>
<option value="chart2">Chart #2</option>
<option value="chart3">Chart #3</option>
</select>
<div id="chart1" class="chartBoxSingle" style="display: none;"></div>
<div id="chart2" class="chartBoxSingle" style="display: none;"></div>
<div id="chart3" class="chartBoxSingle" style="display: none;"></div>
</div>
and here is js part where selects the first option on page load
var currentChart;
function showChart( divid ) {
if (currentChart !== undefined)
currentChart.style.display = "none";
if ( divid ) {
currentChart = document.getElementById(divid);
currentChart.style.display = "block";
}
else {
currentChart = undefined;
}
}
$(document).ready(function() { showChart('chart1'); });
You have to call the chart object's validateSize method when toggling the display of a chart from none to block as shown in this example that uses tabs. Here's another example using your structure:
var charts = {};
charts["chart1"] = AmCharts.makeChart("chart1", {
type: "serial",
dataProvider: [{
"value": 1,
"category": "Category 1"
}, {
"value": 2,
"category": "Category 2"
}, {
"value": 3,
"category": "Category 3"
}],
categoryField: "category",
graphs: [{
valueField: "value",
type: "column",
fillAlphas: .8
}]
});
charts["chart2"] = AmCharts.makeChart("chart2", {
type: "pie",
dataProvider: [{
"value": 2,
"title": "Slice 1"
}, {
"value": 2,
"title": "Slice 2"
}, {
"value": 2,
"category": "Slice 3"
}],
titleField: "title",
valueField: "value"
});
var currentChart;
function showChart(divid) {
if (currentChart !== undefined)
currentChart.style.display = "none";
if (divid) {
currentChart = document.getElementById(divid);
currentChart.style.display = "block";
charts[divid].validateSize();
} else {
currentChart = undefined;
}
}
$(document).ready(function() {
showChart('chart1');
});
.chartBoxSingle {
width: 100%;
height: 400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="//www.amcharts.com/lib/3/amcharts.js"></script>
<script type="text/javascript" src="//www.amcharts.com/lib/3/serial.js"></script>
<script type="text/javascript" src="//www.amcharts.com/lib/3/pie.js"></script>
<div class="chartWrapper" id="chartSingleTest1">
<select onchange="showChart(this.options[this.selectedIndex].value);">
<option value="chart1">Chart #1</option>
<option value="chart2">Chart #2</option>
</select>
<div id="chart1" class="chartBoxSingle" style="display: none;"></div>
<div id="chart2" class="chartBoxSingle" style="display: none;"></div>
</div>

how to assign dynamic value in canvasjs chart using angularjs

how to show dynamic data in canvasjs using angularjs. im getting data from api and want to display in chart. i don't know how to assign variable to the y points of chart.im getting the value and stored in the variable "ValueinCm" instead of static variable need to assign dynamic value.
<script src="http://canvasjs.com/assets/script/canvasjs.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script>
var filledValue;
var app = angular.module('myApp', ["ng-fusioncharts"])
app.controller('MyController', function ($scope, $http) {
$http.get('https://example.com', {
headers: { 'Authorization': 'Basic password==' }
})
.then(function (response) {
$scope.names = response.data;
$scope.decodedFrame = atob($scope.names.dataFrame);
$scope.decodedFrameNew = $scope.decodedFrame.substring(4);
$scope.distanceinFeet = $scope.decodedFrameNew * 12.5*2.54;
$scope.Value = $scope.distanceinFeet / 148;
$scope.ValueinCm = $scope.Value.toFixed(2);
filledValue = $scope.ValueinCm;
console.log(filledValue);
});
});
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
theme: "theme2",//theme1
title: {
text: "Basic Column Chart - CanvasJS"
},
animationEnabled: false, // change to true
data: [
{
// Change type to "bar", "area", "spline", "pie",etc.
type: "column",
dataPoints: [
{ label: "apple", y: filledValue },
{ label: "orange", y: 15 },
{ label: "banana", y: 25 },
{ label: "mango", y: 30 },
{ label: "grape", y: 28 }
]
}
]
});
chart.render();
}
</script>
</head>
<body ng-app="myApp">
<div ng-controller="MyController">
<div id="chartContainer" style="height: 300px; width: 100%;"></div></div>
</body>
After fetching the data, you need to store it into a variable(say, data) which should be an array of objects. You need to make sure, this variable stores the data in CanvasJS prescribed format.
Later you can use this variable in place of your static data.
dataPoints: data
Here is a working jsFiddle

Kendo chart performance issue

I am working on kendo chart. I am loading 30k data on the chart.
You can see in the code I have attached that, when I zoom in and out with mouse scroll, the process becomes very slow. Is it possible to reduce time of execution for each processes? And also first time loading of the chart is also very slow.
I want to know that is 30k data on Kendo chart should be loaded? Is there any limit that Kendo has set for data loading on the chart?
var Chartdata = [];
function createChart() {
$("#chart").kendoChart({
dataSource: {
data: Chartdata
},
series: [{
type: "scatterLine",
xField: "date",
yField: "close"
}, {
type: "scatterLine",
xField: "date",
yField: "volume"
}, {
type: "scatterLine",
xField: "date",
yField: "high"
}, {
type: "scatterLine",
xField: "date",
yField: "low"
}, {
type: "scatterLine",
xField: "date",
yField: "open"
}, {
type: "scatterLine",
xField: "date",
yField: "symbol"
}],
xAxis: {
name: "Date",
baseUnit: "minutes",
BaseUnitSteps: {
second: [1]
},
labels: {
visible: true,
step: 50,
font: "8px Arial,Helvetica,sans-serif",
template: "#= kendo.toString(new Date(value), 'MM/dd/yyyy HH:mm:ss') #"
},
majorUnit: 1,
majorTickType: "none",
majorGridLines: {
step: 5,
},
minorGridLines: {
visible: true,
step: 1,
},
minorTickType: "none",
majorTickType: "none",
},
yAxis: {
majorUnit: 25,
majorTickType: "none",
majorGridLines: {
step: 1,
},
minorGridLines: {
visible: true,
step: 1,
},
minorTickType: "none",
majorTickType: "none",
},
transitions: false,
zoomable: {
mousewheel: {
lock: "y"
},
selection: {
lock: "y"
}
},
zoom: setRange,
}).data("kendoChart");
}
function setRange(e) {
var chart = e.sender;
var options = chart.options;
e.originalEvent.preventDefault();
var xRange = e.axisRanges.Date;
if (xRange) {
var xMinonzoom = xRange.min;
var xMaxonzoom = xRange.max;
var dMaxonzoom = new Date(xMaxonzoom.getYear(), xMaxonzoom.getMonth(), xMaxonzoom.getDay(), xMaxonzoom.getHours(), xMaxonzoom.getMinutes(), xMaxonzoom.getSeconds());
var dMinonzoom = new Date(xMinonzoom.getYear(), xMinonzoom.getMonth(), xMinonzoom.getDay(), xMinonzoom.getHours(), xMinonzoom.getMinutes(), xMinonzoom.getSeconds());
var diff = dMaxonzoom - dMinonzoom;
if (xMaxonzoom - xMinonzoom < 10) {
return;
}
options.xAxis.min = xMinonzoom;
options.xAxis.max = xMaxonzoom;
chart.refresh();
}
}
$(document).ready(function() {
$.ajax({
type: "GET",
cache: true,
url: "https://api.myjson.com/bins/1uan0",
async: false
}).success(function(result) {
var dataresult = result;
$(dataresult).each(function(e, data) {
Chartdata.push({
"date": new Date(Date.parse(data.date)),
"close": data.close,
"volume": data.volume,
"high": data.high,
"low": data.low,
"open": data.open,
"symbol": data.symbol
});
});
createChart();
});
});
#chart circle {
display: none;
}
<link href="http://cdn.kendostatic.com/2015.1.318/styles/kendo.mobile.all.min.css" rel="stylesheet" />
<link href="http://cdn.kendostatic.com/2015.1.318/styles/kendo.common.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://kendochart.webashlar.com/kendochart/Javascripts/kendo.all.min.js"></script>
<div id="chart"></div>
Thank you
I have created a dojo for you so hopefully this points you to the right direction.
Chart Dojo
All I have done is added in some simple filtering so that based on the min and max zoom you have selected for the grid it will only call those items into the datasource for you rather than the entire dataset.
This is achieved via this bit of code:
var datasource = chart.dataSource;
console.log("DataSource Total before Filtering is:: " + datasource.total());
datasource.filter();
datasource.filter([{field:"date", operator:"gte",value : xMinonzoom }, {field:"date", operator: "lte", value:xMaxonzoom}]);
console.log("DataSource Total after Filtering is:: " + datasource.total());
So this shows you the effect the filtering is having on the data source you are returning back.
If you wanted to speed things up further you could potentially look at grouping for larger data sets i.e. when you first load the grid up as the data to me at that point is just noise (in my opinion) and is not really meaningful to me (but it maybe in your use case).
Think how mapping works with instances zoomed out summarized as a number rather than trying to show all the individual data points until you start zooming in and seeing the data individually.
If you need more info then let me know and I will expand the answer/ provide more info if I can.

Kendo Grid wouldn't sort when using Key/Value pair array object

I am using Telerik Kendo Grid; it wouldn't allow to use the sortable functionality of the table when my datasource (array) looks as below:
var myArray = [
{ Destination = { Country: "United Kingdom", AircraftTypeCount: 9 }, Origin= [ {​Country: "United States", Code: "JFK"} ] },
{ Destination = { Country: "Egypt", AircraftTypeCount: ​5 }, Origin= [ {​Country: "​Qatar", Code: "QR"} ] }]
It renders the country column fine, but when I click on the column the sorting doesn't occur. Below is my Kendo Grid (using AngularJS):
$("#myKendoTable").kendoGrid({
dataSource: {
data: myArray
},
sortable: {
mode: "multiple",
allowUnsort: true
},
columns: [
{
field: "Country",
title: "Country",
width: 300,
template: function (item) {
return item["Destination"].Country;
}
}
]
});
​
I've just sorted this out. It seems that Kendo's sorting functionality recognises basic array structure, so I had retrieve all Destinations from myArray into a separate array, and use that new array as the datasource.
I used the following method to do so (using underscoreJS):
function getDestinationsData(airlineRoutes)
{
return _.map(AirlineDestinationRoutes, function (airlineRoutes) { return airlineRoutes.Destination });
}

Resources