我正在使用jVectorMaps.我有一个带有backgroundColor属性的地图对象:
map = new jvm.Map({
container: $('#map'),
map: "world_mill_en,
backgroundColor: bgcolor
Run Code Online (Sandbox Code Playgroud)
假设我声明了一个全局bgcolor变量.然后,我在某个时候更改该变量的值:
function changeBGcolor() {
bgcolor = "yellow";
}
Run Code Online (Sandbox Code Playgroud)
我的想法是,当我更改bgcolor变量的值时,jVectorMap背景颜色会发生变化.到目前为止,我无法做到这一点.
怎么做到呢?
我有三个按钮,每个按钮chooseMap()功能onclick,然后根据按钮将用户重定向到新页面id.一切正常但我每次都要点击两次.谁能告诉我为什么会这样,以及我如何解决它?
<div class="row text-center" onclick="chooseMap();">
<div class="col-md-4">
<button type="button" class="btn btn-primary" id="world" >World Map</button>
</div>
<div class="col-md-4">
<button type="button" class="btn btn-primary" id="europe">Europe</button>
</div>
<div class="col-md-4">
<button type="button" class="btn btn-primary" id="sweden">Sweden</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
function chooseMap(){
$(document).ready(function() {
document.getElementById("sweden").onclick = function(){
location.href = "map_game/sweden.html";
}
document.getElementById("europe").onclick = function(){
location.href="map_game/europe.html";
}
document.getElementById("world").onclick = function(){
location.href="map_game/world.html";
}
})
}
Run Code Online (Sandbox Code Playgroud)
一切正常.我点击按钮,调用函数,传递正确的字符串,我很高兴地发送到下一页,一切都有效.但是,我必须在按钮上单击两次才能使其正常工作.我第一次点击没有任何反应.有什么想法吗?
问题:
我是D3.js的新手,我创建了一个从数组中获取数据的条形图.我将文本放在条形图的顶部,文本比条形图本身宽.我想将它垂直旋转,以便文本穿过条形图的中间.
我知道.attr("transform", "rotate(180)")不会工作,因为它会将我的文字旋转到屏幕外.我在这里找到了Mike Bostock的答案,但它似乎对我不起作用,我不知道我做错了什么.他说我需要改变原点的旋转点,但我不能让它起作用.
任何帮助表示赞赏,您可以在下面找到以下代码:
var label = svg.selectAll("text")
.data(data)
.enter()
.append("text")
.text(function(d){
return d;
})
.attr("x", function(d, i){
xText = i*(w/data.length);
return xText;
})
.attr("y", function(d){
yText = h - yScale(d);
return yText;
})
.attr("transform", "translate(" + xText + "," + yText + ") rotate(90)")
.attr("fill", "black")
.attr("font-family", "sans-serif")
.attr("font-size", "11px");
Run Code Online (Sandbox Code Playgroud)
谢谢!