javascript – 为什么我看不到Raphael.js饼图演示中的颜色?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 为什么我看不到Raphael.js饼图演示中的颜色?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2743字,纯文字阅读大概需要4分钟。
内容图文
我在http://jsfiddle.net/s6dEW/复制了拉斐尔饼图演示:
Raphael.fn.pieChart = function (cx, cy, r, values, labels, stroke) {
var paper = this,
rad = Math.PI / 180,
chart = this.set();
function sector(cx, cy, r, startAngle, endAngle, params) {
var x1 = cx + r * Math.cos(-startAngle * rad),
x2 = cx + r * Math.cos(-endAngle * rad),
y1 = cy + r * Math.sin(-startAngle * rad),
y2 = cy + r * Math.sin(-endAngle * rad);
return paper.path(["M", cx, cy, "L", x1, y1, "A", r, r, 0, +(endAngle - startAngle > 180), 0, x2, y2, "z"]).attr(params);
}
var angle = 0,
total = 0,
start = 0,
process = function (j) {
var value = values[j],
angleplus = 360 * value / total,
popangle = angle + (angleplus / 2),
color = Raphael.hsb(start, .75, 1),
ms = 500,
delta = 30,
bcolor = Raphael.hsb(start, 1, 1),
p = sector(cx, cy, r, angle, angle + angleplus, {
fill: "90-" + bcolor + "-" + color,
stroke: stroke,
"stroke-width": 3
}),
txt = paper.text(cx + (r + delta + 55) * Math.cos(-popangle * rad), cy + (r + delta + 25) * Math.sin(-popangle * rad), labels[j]).attr({
fill: bcolor,
stroke: "none",
opacity: 0,
"font-size": 20
});
p.mouseover(function () {
p.stop().animate({
transform: "s1.1 1.1 " + cx + " " + cy
}, ms, "elastic");
txt.stop().animate({
opacity: 1
}, ms, "elastic");
}).mouseout(function () {
p.stop().animate({
transform: ""
}, ms, "elastic");
txt.stop().animate({
opacity: 0
}, ms);
});
angle += angleplus;
chart.push(p);
chart.push(txt);
start += .1;
};
for (var i = 0, ii = values.length; i < ii; i++) {
total += values[i];
}
for (i = 0; i < ii; i++) {
process(i);
}
return chart;
};
$(function () {
var values = [],
labels = [],
json = [{
"units": "",
"total": "1682.59",
"lbs": "82500.00",
"material": "stainless steel"
}, {
"units": "345",
"total": "18076.19",
"lbs": "49110.50",
"material": "aluminum"
}, {
"units": "480",
"total": "6793.75",
"lbs": "6950.00",
"material": "cardboard cores"
}, {
"units": "",
"total": "353.44",
"lbs": "3482.50",
"material": "scrap metal"
}]
for (i = 0; i < json.length; i++) {
labels.push(json[i].material);
values.push(parseFloat(json[i].lbs));
}
Raphael("holder", 700, 700).pieChart(350, 350, 200, values, labels, "#fff");
});
但是,当我在我的网站(http://www.completerecycling.com/test)上放置相同的代码时,我得到的是Chrome中的黑色饼图和Firefox中的透明饼图,而不是彩色饼图切片.我在做什么不同的方式打破了配色方案?
解决方法:
这是因为< base>您网站上的标记.
Raphaël使用id来引用填充颜色(每个彩色饼图的fill =“url(#…)”属性).
这些引用不适用于http://www.completerecycling.com/test,因为它们解析为http://www.completerecycling.com/test/(base href)加上#…作为颜色定义(而不是http: //www.completerecycling.com/test#…).
要么将基础href更改为http://www.completerecycling.com/test而不使用尾部斜杠,请完全删除基本标记或将http://www.completerecycling.com/test重定向到http://www.completerecycling.com / test /(工作正常).
内容总结
以上是互联网集市为您收集整理的javascript – 为什么我看不到Raphael.js饼图演示中的颜色?全部内容,希望文章能够帮你解决javascript – 为什么我看不到Raphael.js饼图演示中的颜色?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。