样式在 Mozilla Firefox 中不起作用

亚历山大·巴拉诺夫

我想建立堆叠图表栏。为了构建它,我使用的是 d3js 版本 3。我在 codepen 上找到了一些模板并根据我的需要进行了更改。

当我在 Chrome 中打开条形图时,它看起来不错: 在此处输入图片说明

但是当我在 Mozilla Firefox 中打开它时,它显示没有颜色: 在此处输入图片说明

我应该修复什么才能使样式起作用?

这是我的 html 和 javascript 代码:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>d3.js learning</title>
    <script data-require="[email protected]" data-semver="3.0.0" src="https://d3js.org/d3.v3.min.js"></script>

  <style type="text/css">
  svg {
    font: 10px sans-serif;
    shape-rendering: crispEdges;
  }

  .axis path,
  .axis line {
    fill: none;
    stroke: #000;
  }

  path.domain {
    stroke: none;
  }

  .y .tick line {
    stroke: #ddd;
  }
  </style>

</head>
<body>
<script>

// Setup svg using Bostock's margin convention

/* Data in strings like it would be if imported from a csv */

var data = [
  { year: "2006", pid: "10", eid: "15"},
  { year: "2007", pid: "12", eid: "18"},
  { year: "2008", pid: "05", eid: "20"},
  { year: "2009", pid: "01", eid: "15"},
  { year: "2010", pid: "02", eid: "10"},
  { year: "2011", pid: "03", eid: "12"},
  { year: "2012", pid: "04", eid: "15"},
  { year: "2013", pid: "06", eid: "11"},
  { year: "2014", pid: "10", eid: "13"},
  { year: "2015", pid: "16", eid: "19"},

];

var margin = {top: 20, right: 160, bottom: 35, left: 30};

var width = 1000 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;

var svg = d3.select("body")
  .append("svg")
  .attr("width", width + margin.left + margin.right)
  .attr("height", height + margin.top + margin.bottom )
  .append("g")
  .attr("transform", "translate(" + margin.left + "," + margin.top + ")");




var parse = d3.time.format("%Y").parse;


// Transpose the data into layers
var dataset = d3.layout.stack()(["pid", "eid"].map(function(id) {
  return data.map(function(d) {
    return {x: parse(d.year), y: +d[id]};
  });
}));


// Set x, y and colors
var x = d3.scale.ordinal()
  .domain(dataset[0].map(function(d) { return d.x; }))
  .rangeRoundBands([10, width-10], 0.20);

var y = d3.scale.linear()
  .domain([0, d3.max(dataset, function(d) {  return d3.max(d, function(d) { return d.y0 + d.y; });  })])
  .range([height, 0]);

var colors = [ "3d3756", "574e7c"];


// Define and draw axes
var yAxis = d3.svg.axis()
  .scale(y)
  .orient("left")
  .ticks(5)
  .tickSize(-width, 0, 0)
  .tickFormat( function(d) { return d } );

var xAxis = d3.svg.axis()
  .scale(x)
  .orient("bottom")
  .tickFormat(d3.time.format("%Y"));

svg.append("g")
  .attr("class", "y axis")
  .call(yAxis);

svg.append("g")
  .attr("class", "x axis")
  .attr("transform", "translate(0," + height + ")")
  .call(xAxis)
  .selectAll("text")
    .style("text-anchor", "end")
    .attr("dx", "-.8em")
    .attr("dy", ".15em")
    .attr("transform", "rotate(-65)");;


// Create groups for each series, rects for each segment
var groups = svg.selectAll("g.cost")
  .data(dataset)
  .enter().append("g")
  .attr("class", "cost")
  .style("fill", function(d, i) { return colors[i]; });

var rect = groups.selectAll("rect")
  .data(function(d) { return d; })
  .enter()
  .append("rect")
  .attr("x", function(d) { return x(d.x); })
  .attr("y", function(d) { return y(d.y0 + d.y); })
  .attr("height", function(d) { return y(d.y0) - y(d.y0 + d.y); })
  .attr("width", x.rangeBand())
  .on("mouseover", function() { tooltip.style("display", null); })
  .on("mouseout", function() { tooltip.style("display", "none"); })
  .on("mousemove", function(d) {
    var xPosition = d3.mouse(this)[0] - 15;
    var yPosition = d3.mouse(this)[1] - 25;
    tooltip.attr("transform", "translate(" + xPosition + "," + yPosition + ")");
    tooltip.select("text").text(d.y);
  });


// Draw legend
var legend = svg.selectAll(".legend")
  .data(colors)
  .enter().append("g")
  .attr("class", "legend")
  .attr("transform", function(d, i) { return "translate(30," + i * 19 + ")"; });

legend.append("rect")
  .attr("x", width - 18)
  .attr("width", 18)
  .attr("height", 18)
  .style("fill", function(d, i) {return colors.slice().reverse()[i];});

legend.append("text")
  .attr("x", width + 5)
  .attr("y", 9)
  .attr("dy", ".35em")
  .style("text-anchor", "start")
  .text(function(d, i) {
    switch (i) {
      case 0: return "EID";
      case 1: return "PID";
    }
  });


// Prep the tooltip bits, initial display is hidden
var tooltip = svg.append("g")
  .attr("class", "tooltip")
  .style("display", "none");

tooltip.append("rect")
  .attr("width", 30)
  .attr("height", 20)
  .attr("fill", "white")
  .style("opacity", 0.5);

tooltip.append("text")
  .attr("x", 15)
  .attr("dy", "1.2em")
  .style("text-anchor", "middle")
  .attr("font-size", "12px")
  .attr("font-weight", "bold");

</script>
</body>
</html>

亚历山大·巴拉诺夫

通过向颜色添加哈希来修复它:

从:

const all_colors = ["3d3756", "f0ee42", "f4c7de"];

至:

const all_colors = ["#3d3756", "#f0ee42", "#f4c7de"];

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

SVG在Mozilla Firefox中不起作用

来自分类Dev

字体样式在Firefox中不起作用

来自分类Dev

隐藏滚动条在 Mozilla Firefox 中不起作用

来自分类Dev

Mozilla Firefox鼠标中键不起作用

来自分类Dev

首字下沉样式在Firefox中不起作用

来自分类Dev

firefox css 选项样式不起作用

来自分类Dev

产生的效果在mozilla firefox上不起作用

来自分类Dev

Google登录API在Mozilla Firefox上不起作用

来自分类Dev

Mozilla Firefox中的错误。

来自分类Dev

缩放后svg过滤器在mozilla firefox中不起作用

来自分类Dev

CSS3关键帧动画在Mozilla Firefox中不起作用

来自分类Dev

Button with在Mozilla Firefox和Google Chorme中均不起作用

来自分类Dev

CSS 3D效果在Mozilla FireFox中不起作用

来自分类Dev

角ng-repeat $ index在mozilla firefox上的ng-if指令中不起作用

来自分类Dev

覆盖CSS过滤器反转功能在Mozilla Firefox中不起作用

来自分类Dev

HTML 显示和隐藏在 Mozilla Firefox 中不起作用

来自分类Dev

在 php 中从 mozilla firefox 上传音频文件不起作用

来自分类Dev

我的表单上的CSS样式在Firefox上不起作用

来自分类Dev

HTML正文样式“ padding-top”在Firefox中不起作用

来自分类Dev

FieldSet CSS 样式不适用于 Mozilla Firefox

来自分类Dev

在Mozilla Firefox中识别“事件”

来自分类Dev

在Mozilla Firefox中查看Cookies

来自分类Dev

<img>标记在Mozilla Firefox和IE上不起作用...更改斜杠对我不起作用

来自分类Dev

.focus()onblur在Mozilla中不起作用

来自分类Dev

动画在Mozilla中不起作用

来自分类Dev

Backgroud CSS在Mozilla中不起作用

来自分类Dev

CSS3过滤器在Opera,Internet Explorer,Mozilla Firefox上不起作用

来自分类Dev

CSS过滤器invert()在Mozilla FireFox上不起作用?

来自分类Dev

透视图属性(css3)在Mozilla Firefox浏览器上不起作用

Related 相关文章

  1. 1

    SVG在Mozilla Firefox中不起作用

  2. 2

    字体样式在Firefox中不起作用

  3. 3

    隐藏滚动条在 Mozilla Firefox 中不起作用

  4. 4

    Mozilla Firefox鼠标中键不起作用

  5. 5

    首字下沉样式在Firefox中不起作用

  6. 6

    firefox css 选项样式不起作用

  7. 7

    产生的效果在mozilla firefox上不起作用

  8. 8

    Google登录API在Mozilla Firefox上不起作用

  9. 9

    Mozilla Firefox中的错误。

  10. 10

    缩放后svg过滤器在mozilla firefox中不起作用

  11. 11

    CSS3关键帧动画在Mozilla Firefox中不起作用

  12. 12

    Button with在Mozilla Firefox和Google Chorme中均不起作用

  13. 13

    CSS 3D效果在Mozilla FireFox中不起作用

  14. 14

    角ng-repeat $ index在mozilla firefox上的ng-if指令中不起作用

  15. 15

    覆盖CSS过滤器反转功能在Mozilla Firefox中不起作用

  16. 16

    HTML 显示和隐藏在 Mozilla Firefox 中不起作用

  17. 17

    在 php 中从 mozilla firefox 上传音频文件不起作用

  18. 18

    我的表单上的CSS样式在Firefox上不起作用

  19. 19

    HTML正文样式“ padding-top”在Firefox中不起作用

  20. 20

    FieldSet CSS 样式不适用于 Mozilla Firefox

  21. 21

    在Mozilla Firefox中识别“事件”

  22. 22

    在Mozilla Firefox中查看Cookies

  23. 23

    <img>标记在Mozilla Firefox和IE上不起作用...更改斜杠对我不起作用

  24. 24

    .focus()onblur在Mozilla中不起作用

  25. 25

    动画在Mozilla中不起作用

  26. 26

    Backgroud CSS在Mozilla中不起作用

  27. 27

    CSS3过滤器在Opera,Internet Explorer,Mozilla Firefox上不起作用

  28. 28

    CSS过滤器invert()在Mozilla FireFox上不起作用?

  29. 29

    透视图属性(css3)在Mozilla Firefox浏览器上不起作用

热门标签

归档