- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 omnivore 在 mapbox 中使用来自 CSV 文件的标记点创建 map 。我已经成功地弄清楚了如何在每个标记的弹出窗口中添加 highcharts map ,但我无法让它从同一个 CSV 中提取数据。我已经想出了如何添加 Highcharts ,但只能通过粘贴数据来添加,但是我不想手动添加系列数据,而是想从现有的 CSV 文件中提取数据,并按年份遍历每一列以获取 Highcharts 弹出窗口。
有人可以帮我从我的 CSV 数据中添加一个系列吗?尝试复制失败。
这是我当前的工作示例(highcharts 弹出窗口不使用我的 CSV 文件中的数据):
(也在 jfiddle 上,但您需要在本地添加 csv :) https://jsfiddle.net/mofq60zq/
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Styled markers from CSV data</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src="jquery1.6.4.min.js"></script><!-- jquery-1.6.4.min.js -->
<script src="jqueryui1.8.16.custom.min.js"></script><!-- jquery-ui-1.8.16.custom.min.js -->
<script src='https://api.mapbox.com/mapbox.js/v2.2.4/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v2.2.4/mapbox.css' rel='stylesheet' />
<script src='https://cdnjs.cloudflare.com/ajax/libs/highcharts/4.1.1/highcharts.js'></script>
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
.search-ui {
position:absolute;
top:10px;
right:10px;
z-index:1000;
}
.sparkline {
height: 100px;
width: 200px;
}
</style>
</head>
<body>
<script src='https://api.mapbox.com/mapbox.js/plugins/leaflet-omnivore/v0.2.0/leaflet-omnivore.min.js'></script>
<div id='map'></div>
<input id='search' class='search-ui' placeholder='Enter country code' />
<script>
L.mapbox.accessToken = 'pk.eyJ1IjoiZXRwLXByb2plY3QiLCJhIjoiY2lqbDc0dWQwMDAxeHUya280OTE5dGs0NCJ9.viXLMvWxmTv3_uZyvjKsOA';
var map = L.mapbox.map('map', 'mapbox.streets')
.setView([49.4987919, 13.9583693], 4);
// omnivore will AJAX-request this file behind the scenes and parse it:
// note that there are considerations:
// - The CSV file must contain latitude and longitude values, in column
// named roughly latitude and longitude
// - The file must either be on the same domain as the page that requests it,
// or both the server it is requested from and the user's browser must
// support CORS.
// The omnivore functions take three arguments:
//
// - a URL of the file to fetch
// - options to the parser
// - a custom layer
//
// And they return the custom layer, which is by default an L.geoJson layer.
//
// The second two arguments are each optional. In this case we're supplying
// no arguments to the parser (null), but supplying a custom layer:
// an instance of L.mapbox.featureLayer
// This means that rows with simplestyle properties will be styled as they
// would be in GeoJSON and elsewhere.
//omnivore.csv('gtftest.csv', null, L.mapbox.featureLayer()).addTo(map);
omnivore.csv('gtftest.csv')
.on('ready', function(layer) {
this.eachLayer(function(marker) {
if (marker.toGeoJSON().properties.Type === 'H') {
marker.setIcon(L.mapbox.marker.icon({
'marker-color': '#ff8888',
'marker-size': 'small',
'marker-image': 'H.png'
}));
} else if (marker.toGeoJSON().properties.Type === 'LNG') {
// The argument to L.mapbox.marker.icon is based on the
// simplestyle-spec: see that specification for a full
// description of options.
marker.setIcon(L.mapbox.marker.icon({
'marker-color': '#ff0000',
'marker-size': 'small',
'marker-image': 'LNG.png'
}));
}
else {
marker.setIcon(L.mapbox.marker.icon({}));
}
////HIGHCHARTS HERE////
var lineChartOptions = {
title: {
text: null
},
legend: {
enabled: false
},
credits: {
enabled: false
},
exporting: {
enabled: false
},
tooltip: {
backgroundColor: {
linearGradient: [0, 0, 0, 60],
stops: [
[0, '#FFFFFF'],
[1, '#E0E0E0']
]
},
borderWidth: 1,
useHTML: true,
borderColor: '#AAA'
},
yAxis: {
min: 0,
lineWidth: 1,
tickWidth: 1,
title: {
text: null
},
labels: {
style: {
'fontSize': '10px'
}
}
},
xAxis: {
type: 'datetime',
labels: {
style: {
'fontSize': '10px'
}
}
},
plotOptions: {
series: {
cursor: 'pointer',
connectNulls: false
}
}
};
lineChartOptions.tooltip.formatter = function() {
var y = "$" + this.y;
return '<center>' + Highcharts.dateFormat('%b \'%y', new Date(this.x)) + '</center></b><center><b>' + y + '</b></center>';
};
lineChartOptions.series = [{
pointInterval: 24 * 3600 * 1000 * 30.41667,
pointStart: 1393632000000,
data: [
58044, 60871, 29738, null, 804997, 628727, 20678, null,
100606, 122195, 981459, 39840]
}];
// HTML content for port pop-up
var popupContent = '<div id="popup_template">' +
'<div class="port_header marker-title">' +marker.toGeoJSON().properties.Borderpoint +'</div>' +
'<div class="est_value marker-title">'+
'Est. Value: $' + marker.toGeoJSON().properties.Value
+'</div>' +
'<div id="est_value_sparkline" class="sparkline"></div>';
var container = $('<div id="popup_template"/>');
container.html( '<div class="port_header marker-title">' +marker.toGeoJSON().properties.Borderpoint +'</div>' +
'<div class="est_value marker-title">'+
'Est. Value: $' + marker.toGeoJSON().properties.Value
+'</div>' +
'<div id="est_value_sparkline" class="sparkline"></div>');
// Delegate all event handling for the container itself and its contents to the container
container.find('#est_value_sparkline').highcharts(lineChartOptions);
marker.bindPopup(container[0]);
//});
///END HIGHCHARTS
});
})
.addTo(map);
</script>
</body>
</html>
这是我的 CSV 文件,我也想将其用于图表:
Borderpoint,Exit,Entry,Value,Type,Lat,Lon,Oct-08,Nov-08,Dec-08,Jan-09,Feb-09,Mar-09,Apr-09,May-09,Jun-09,Jul-09,Aug-09,Sep-09,Oct-09,Nov-09,Dec-09,Jan-10,Feb-10,Mar-10,Apr-10,May-10,Jun-10,Jul-10,Aug-10,Sep-10,Oct-10,Nov-10,Dec-10,Jan-11,Feb-11,Mar-11,Apr-11,May-11,Jun-11,Jul-11,Aug-11,Sep-11,Oct-11,Nov-11,Dec-11,Jan-12,Feb-12,Mar-12,Apr-12,May-12,Jun-12,Jul-12,Aug-12,Sep-12,Oct-12,Nov-12,Dec-12,Jan-13,Feb-13,Mar-13,Apr-13,May-13,Jun-13,Jul-13,Aug-13,Sep-13,Oct-13,Nov-13,Dec-13,Jan-14,Feb-14,Mar-14,Apr-14,May-14,Jun-14,Jul-14,Aug-14,Sep-14,Oct-14,Nov-14,Dec-14,Jan-15,Feb-15,Mar-15,Apr-15,May-15,Jun-15,Jul-15,Aug-15,Sep-15,Oct-15
Adriatic LNG,Liquefied Natural Gas,Italy,1.10,LNG,45.057529,12.247078,0,0,0,0,0,0,0,0,0,0,0,0,331,456,656,602,581,657,622,608,439,582,529,627,556,648,638,625,616,637,659,685,646,623,405,490,577,531,575,598,493,657,601,581,497,396,269,594,401,556,563,514,544,503,463,416,488,542,357,273,486,321,442,352,363,265,360,536,442,536,178,115,510,353,437,623,531,435,531,538,435,397,490,448,532
Almeria,Algeria,Spain,0.93,H,36.8392791,-2.4699896,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,220,257,280,219,142,280,272,256,241,297,336,347,237,288,254,196,171,222,348,362,394,449,487,570,588,532,483,513,324,482,609,607,607,621,576,613,542,520,544,412,395,533,603,557,562,552,435,403,569,516,530,586,616,569,635
Alveringem,Belgium,France,N/A,H,51.0167,2.7167,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Alveringem,France,Belgium,N/A,H,51.0167,2.7167,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5
Badajoz,Spain,Portugal,0.50,H,38.8789,-7.0084523,153,183,85,199,104,9,190,0,0,0,0,0,189,178,247,249,239,246,84,188,145,179,144,159,178,200,244,226,205,213,167,291,291,58,157,203,264,170,103,200,248,254,244,225,218,104,121,147,145,242,230,247,198,209,238,129,139,233,141,179,239,240,222,230,243,280,225,243,193,200,227,262,277,226,146,277,140,141,248,278,325,329,298,294,270
Badajoz,Portugal,Spain,0.50,H,38.8789,-7.0084523,0,0,0,0,12,2,0,0,0,0,0,0,3,9,10,5,4,2,0,0,0,1,22,24,22,24,48,0,0,0,0,0,0,0,0,9,0,0,0,0,0,8,1,2,0,0,0,0,0,8,12,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
我想做的是用我的 CSV 文件中的数据替换弹出窗口中的折线图(使用标题 Oct '08 -Oct 15 - columns 8++ 中的数据)但我找不到添加的方法使用杂食 CSV 到 GeoJSON 的系列 - 有人可以帮我在我的标记弹出窗口中绘制这张图吗?谢谢!
最佳答案
好的,所以当 omnivore 导入你的 csv 文件时,它会将每一行的所有数据作为 javascript 对象的属性。问题是你想显示时间序列数据(意思是来自你的 csv 的有序数据),但是 javascript 对象中的键没有固有的顺序。因此,您不能只是遍历键并期望顺序是正确的。
所以我从你的 csv 中获取了关键顺序,并将其声明为一个数组,如下所示
var keyOrder = ["Oct-08","Nov-08","Dec-08","Jan-09","Feb-09","Mar-09","Apr-09","May-09","Jun-09","Jul-09","Aug-09","Sep-09","Oct-09","Nov-09","Dec-09","Jan-10","Feb-10","Mar-10","Apr-10","May-10","Jun-10","Jul-10","Aug-10","Sep-10","Oct-10","Nov-10","Dec-10","Jan-11","Feb-11","Mar-11","Apr-11","May-11","Jun-11","Jul-11","Aug-11","Sep-11","Oct-11","Nov-11","Dec-11","Jan-12","Feb-12","Mar-12","Apr-12","May-12","Jun-12","Jul-12","Aug-12","Sep-12","Oct-12","Nov-12","Dec-12","Jan-13","Feb-13","Mar-13","Apr-13","May-13","Jun-13","Jul-13","Aug-13","Sep-13","Oct-13","Nov-13","Dec-13","Jan-14","Feb-14","Mar-14","Apr-14","May-14","Jun-14","Jul-14","Aug-14","Sep-14","Oct-14","Nov-14","Dec-14","Jan-15","Feb-15","Mar-15","Apr-15","May-15","Jun-15","Jul-15","Aug-15","Sep-15","Oct-15"];
然后我用下面的代码替换了您正常的 highchart 初始化,它循环遍历您的属性并以正确的顺序获取值。
var thisData = [];
for (var i = 0; i < keyOrder.length; i++) {
thisData.push(parseInt(marker.feature.properties[keyOrder[i]]));
}
lineChartOptions.series = [{
pointInterval: 24 * 3600 * 1000 * 30.41667,
pointStart: 1393632000000,
data: thisData
}];
You can take a look at the entire file here .这会按照您的预期生成弹出式折线图。
关于javascript - 从 CSV 将 highcharts 添加到 mapbox 弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34915377/
我连续有 11 个图像,如果鼠标悬停在其中一个图像上,我希望弹出一个弹出窗口。所以每 11 个图像都有不同的弹出窗口。我已经有一些代码可以执行此操作,但它仅适用于第一张图像。 代码:index.htm
是否可以从 NSColorWell 制作一个 NSColorPanel“弹出”,几乎像一个弹出菜单? 我不喜欢它作为调色板的实现方式,因为有时它与哪个 NSColorWell 关联并不明显。 谢谢!
我正在考虑一个想法,基本上我想要一个带有 NSPopoverController 的 NSStatusItem 。我读到了人们遇到的所有问题,但我只是想尝试一下。现在有干净的方法吗?我见过的所有版本都
如何获取 JS 打开的弹出窗口的 url。这是我的代码: var _url = 'someurlhere'; var popupwindow = window.open(_url, "Popu
我正在设计一个网页,我希望当用户单击链接时,弹出窗口(新窗口)将打开一个链接网页。我的代码如下所示 function win(add,w,h) { window.open(add,"","widt
我正在寻找 C 中的简单堆栈实现,并找到了类似的东西: void pop(struct stack **top) { struct stack *temp; temp = malloc(s
我正在尝试使用 paypal 实现登录,我有 2 个不同的主机域 1- www.example.com 2- www.example.de 对于 paypal,我需要为此目的选择一个返回 URL,我选
我正在尝试找出如何复制此处显示的“弹出式” View 动画:https://imgur.com/a/irFqdiP .我正在使用当前代码来显示我的 viewController,但目前只有一个淡入淡出
有谁知道在 Windows 2000 或更高版本上以编程方式关闭 CD 托盘的方法?打开 CD 托盘存在,但我似乎无法关闭它,尤其是在 W2k 下。 如果可能的话,我特别想从批处理文件中寻找一种方法来
当您访问http://www.daniweb.com时你得到一个弹出窗口,这叫什么 + 知道怎么做吗? 感谢您的回复,只有模态加载动画的最简单方法是什么,即页面加载时动画显示以及动画何时完成? ASP
我正在为 Unity 引擎中的音频过滤器创建一个 C# 脚本。 我的问题是,在通过我的过滤器运行后,生成的音频具有一致且频繁的“咔哒声”、“砰砰声”或“跳过声”。听起来有点像旧 radio 。 我不确
我必须隐藏浏览器的地址栏。我正在使用这段代码: var winFeature = 'location=no,toolbar=no,menubar=no,scrollbars=yes,r
推荐一个button 弹起pickerview的源码,也可以作为工具类使用。 利用inputview 做键盘弹起动画。该如何做呢? 1.继承uiview 2.重写属性&方法
我在这里有一个问题,我已经工作了几个小时。 我正在导入一个 Excel 文件,并使用此代码来执行此操作: Dim objExcel As Excel.Application Di
我基本上是从 UITableViewController 推送 UIView,它包含的只是 UIWebView。但是,当我删除 UIView 以返回到 UITableView 时,应用程序崩溃了。 -
我有几个由导航 Controller 控制的 View Controller 。 例如,viewController A 和 viewController B 都可以将 viewController
我使用新的Gmail API为用户创建草稿。 API响应提供了新创建的消息ID。 然后,我可以使用URL https://mail.google.com/mail/#drafts?compose=[m
Redis列表实现了哪种内部数据结构以实现这一目的?链表将需要O(n)索引,而数组将需要O(n)左/右推/弹出。 最佳答案 根据official documentation,它们被实现为linked
我正在使用 WPF Popup 控件,它显示背景为黑色。我在其中放置了一个 StackPanel 并设置了 Background="Transparent",但这没有帮助。
我希望页面内的容器在事件时占据页面的整个宽度并覆盖在其他所有内容上。这是我目前所拥有的,但它没有按我想要的方式工作: $(function() { $('.main a').click( fu
我是一名优秀的程序员,十分优秀!