简体   繁体   English

Jquery Mapael:如何使用HTML表格数据替换此硬编码示例?

[英]Jquery Mapael: How can I use HTML table data to replace this hard coded example?

Here is the hard coded code that works (only 2 states): 这是有效的硬编码代码(仅2个状态):

 var myAreas = [];
    myAreas = {
            "VA": {
                value: "6.3",
                tooltip: {  content: "Virginia freq : 7.2"  }
            },
            "NC": {
                value: "5.7",
                tooltip: { content: "North Carolina freq : 6.7" }
            }
        };
        $(".mapcontainer").mapael({
            map: {
                name: "usa_states"
            },
            areas: myAreas
        });

I'm trying to use the results in my HTML table but can't seem to get it into an acceptable format. 我正在尝试使用HTML表中的结果,但似乎无法将其转换为可接受的格式。 This is what I have been trying: 这就是我一直在尝试的:

var data = [];
    var rows = $('#tblStateFreq').find('tr');
    for (var i = 0; i < rows.length; i++) {
        var row = $(rows[i]);
        var state = row.find('td').eq(0).text();
        var freq = row.find('td').eq(1).text();
        data.push({
            state,
            value: freq,
            tooltip: state + " " + freq;
        });
    }
    $(".mapcontainer").mapael({
        map: {
            name: "usa_states"
        },
        areas: data
    });

the data array has all the states with the correct data but it's in the form: 数据数组具有所有具有正确数据的状态,但格式为:

0: state: "AK" tooltip: {content: "AK 7.0"} value: "7.0" 0:状态:“ AK”工具提示:{content:“ AK 7.0”}值:“ 7.0”

I've used this table data approach successfully with flot for line and column charts but the map seems to be trickier. 我已经成功地使用了这种表格数据方法,并用flot制作了折线图和柱形图,但是地图似乎比较棘手。 Can anyone help. 谁能帮忙。 Thanks 谢谢

I found what I was looking for here: Is it possible to add dynamically named properties to JavaScript object? 我在这里找到了想要的东西: 是否可以向JavaScript对象添加动态命名的属性?

although the hard coded data, myAreas[] is originally defined as an array it is redefined as an object, myAreas{...} and properties (states) are added. 尽管硬编码数据myAreas []最初定义为数组,但重新定义为对象,但添加了myAreas {...}和属性(状态)。

In my example I was trying to add to my array data[] using push which worked, but is not what the mapeal plugin wants as the areas argument. 在我的示例中,我试图使用push来将data []添加到我的数组中,但这确实有效,但不是mapeal插件想要作为area参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM