gpt4 book ai didi

javascript - 在图例中显示个人姓名

转载 作者:行者123 更新时间:2023-12-02 23:22:46 26 4
gpt4 key购买 nike

我想在 map 图例中显示城市名称。当我添加“名称”参数时,它只会显示一个。我确实有自己的数据集,但它与 SQL 服务器绑定(bind),因此我使用了plotly 的示例代码,但仍然无法让它出现在那里。

https://codepen.io/anon/pen/LKrLRa

在数据中,我添加了“名称”数组:

   var data = [{
type: 'scattergeo',
mode: 'markers+text',
text: [
'Montreal', 'Toronto', 'Vancouver', 'Calgary', 'Edmonton',
'Ottawa', 'Halifax', 'Victoria', 'Winnepeg', 'Regina'
],
lon: [
-73.57, -79.24, -123.06, -114.1, -113.28,
-75.43, -63.57, -123.21, -97.13, -104.6
],
lat: [
45.5, 43.4, 49.13, 51.1, 53.34, 45.24,
44.64, 48.25, 49.89, 50.45
],
marker: {
size: 7,
color: [
'#bebada', '#fdb462', '#fb8072', '#d9d9d9', '#bc80bd',
'#b3de69', '#8dd3c7', '#80b1d3', '#fccde5', '#ffffb3'
],
line: {
width: 1
}
},
name: [
'Montreal', 'Toronto', 'Vancouver', 'Calgary', 'Edmonton',
'Ottawa', 'Halifax', 'Victoria', 'Winnepeg', 'Regina'
]
}];

在布局中添加 showlegend: true

var layout = {
title: 'Canadian cities',
showlegend: true,
font: {
family: 'Droid Serif, serif',
size: 6
},
titlefont: {
size: 16
},
geo: {
scope: 'north america',
resolution: 50,
lonaxis: {
'range': [-130, -55]
},
lataxis: {
'range': [40, 70]
},
showrivers: true,
rivercolor: '#fff',
showlakes: true,
lakecolor: '#fff',
showland: true,
landcolor: '#EAEAAE',
countrycolor: '#d3d3d3',
countrywidth: 1.5,
subunitcolor: '#d3d3d3'
}
};

最佳答案

这里您的数据列表应包含单独的对象以显示多个图例。这里我尝试了数据中的 3 个对象,并且有 3 个图例。所以你应该正确地制定你的数据列表。

var data = [{
type: 'scattergeo',
mode: 'markers+text',
text: [
'Montreal'
],
lon: [-73.57],
lat: [
45.5
],
marker: {
size: 7,
color: [
'#bebada'
],
line: {
width: 1
}
},
name: 'Montreal',

textposition: [
'top right'
],
}, {
type: 'scattergeo',
mode: 'markers+text',
text: [
'Toronto'
],
lon: [-79.24],
lat: [
43.4
],
marker: {
size: 7,
color: [
'#fdb462'
],
line: {
width: 1
}
},
name: 'Toronto',

textposition: [
'top left'
],
}, {
type: 'scattergeo',
mode: 'markers+text',
text: [
'Vancouver'
],
lon: [-123.06],
lat: [
49.13
],
marker: {
size: 7,
color: [
'#fb8072'
],
line: {
width: 1
}
},
name: 'Vancouver',
textposition: [
'top center'
],
}];


var layout = {
title: 'Canadian cities',
showlegend: true,
font: {
family: 'Droid Serif, serif',
size: 6
},
titlefont: {
size: 16
},
geo: {
scope: 'north america',
resolution: 50,
lonaxis: {
'range': [-130, -55]
},
lataxis: {
'range': [40, 70]
},
showrivers: true,
rivercolor: '#fff',
showlakes: true,
lakecolor: '#fff',
showland: true,
landcolor: '#EAEAAE',
countrycolor: '#d3d3d3',
countrywidth: 1.5,
subunitcolor: '#d3d3d3'
}
};

Plotly.newPlot('myDiv', data, layout, {
showSendToCloud: true
});
<head>
<!-- Plotly.js -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>

<body>
<!-- Plotly chart will be drawn inside this DIV -->
<div id="myDiv"></div>
</body>

关于javascript - 在图例中显示个人姓名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56872962/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com