在Mapbox标记弹出窗口中显示高亮度折线图

时间:2015-02-25 15:27:27

标签: javascript jquery highcharts mapbox

我的目标是在Mapbox弹出窗口中显示两个小的Highchart折线图(高度:100px;)。我在HTML中有两个div来保存图表,如下图所示,它们会显示图表,因为轴显示得很好。

enter image description here

令我感到困惑的是,系列和标记没有显示,除了由y轴分割的第一个标记的一半。检查Chrome中的Highchart元素时,标记和系列的所有路径都显示在正确的位置,并标记为visibility =" visible"。

enter image description here

有没有人遇到过类似的问题?

更新:现场演示 - http://jsfiddle.net/calanoue/tf95sLsu/

<head lang="en">
<title></title>
</head>
<body>
<div id='map'></div>
<script>
...
</script>
</body>

1 个答案:

答案 0 :(得分:3)

我尝试使用此解决方案,它可以帮助你,  JSFiddle

<强> HTML:

<head lang="en">
    <title></title>
</head>
<body>
    <div id='map'></div>

</body>

<强> CSS:

  body {
       margin: 0;
       padding: 0;
   }
   #map {
       position: absolute;
       top: 0;
       bottom: 0;
       width: 100%;
   }

   .sparkline {
       height: 100px;
       width: 200px;
   }

jQuery:

L.mapbox.accessToken = 'pk.eyJ1IjoibmF1dGlseXRpY3MiLCJhIjoidG5tdktlMCJ9.Ktr2w0QzGrAN2UNtrJJziw';

var map = L.mapbox.map('map', 'nautilytics.icjmd18i').setView([37.8, -96], 4);
var myLayer = L.mapbox.featureLayer().addTo(map);

 var portGeoJSON = {
            "type": "FeatureCollection",
                "features": [{
                "type": "Feature",
                    "geometry": {
                    "type": "Point",
                        "coordinates": [-74.0047538280487, 40.7590498275021]
                },
                    "properties": {
                    "title": "NEW YORK",
                        "est_value": 13639833,
                        "marker-color": "#0000ff",
                        "marker-size": "medium",
                        "marker-symbol": "harbor"
                }
            }]
        };

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
                }
            }
        };

myLayer.on('layeradd', function(e) {
    var marker = e.layer,
        feature = marker.feature;


    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 pop-up
           var popupContent = '<div id="popup_template">' +
        '<div class="port_header marker-title">' +e.layer.feature.properties.title.toUpperCase() +'</div>' +
        '<div class="est_value marker-title">'+
               'Est. Value: $' + e.layer.feature.properties.est_value
               +'</div>' +
        '<div id="est_value_sparkline" class="sparkline"></div>';


    var container = $('<div id="popup_template"/>');


    container.html( '<div class="port_header marker-title">' +e.layer.feature.properties.title.toUpperCase() +'</div>' +
        '<div class="est_value marker-title">'+
               'Est. Value: $' + e.layer.feature.properties.est_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]);
});

myLayer.setGeoJSON(portGeoJSON);