d3.js – 内联样式笔画宽度为粗体勾号

前端之家收集整理的这篇文章主要介绍了d3.js – 内联样式笔画宽度为粗体勾号前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我不使用css,因为我想保存并处理创建的SVG可视化文件.这意味着我需要使用内联样式.到目前为止,我经历了d3,因为很有可能我做错了事情.

我期待{‘stroke-width’:’3px’}制作粗轴线.但它使得粗体轴标签.我希望文本被控制与字体相关的样式,如{‘font-style’:’normal’}.

使用“笔画宽度”有什么问题?我在Chrome和Firefox中都进行了测试.

这是我的代码

  1. <script>
  2. var margin = {top: 20,right: 10,bottom: 20,left: 40};
  3. var width = 960 - margin.left - margin.right;
  4. var height = 100 - margin.top - margin.bottom;
  5.  
  6. var x = d3.scale.linear().range([0,width]);
  7. var y = d3.scale.linear().range([0,height]);
  8. var xAxis = d3.svg.axis().scale(x).orient("bottom");
  9. // .tickFormat(d3.time.format("%H:%M"));
  10. var yAxis = d3.svg.axis().scale(y).orient("left").ticks(height/10);
  11.  
  12. var svg = d3.select("svg");
  13. var vis = svg.append("g")
  14. .attr("transform","translate(" + margin.left + "," + margin.top + ")")
  15. .style({'font-size': '10px','font-family': 'sans-serif','font-style': 'normal','font-variant': 'normal','font-weight': 'normal'});
  16.  
  17. var redraw = function(selection,data,style) {
  18. selection.selectAll(".bar")
  19. .data(data)
  20. .enter().append("rect")
  21. .attr('class',"bar")
  22. .attr("x",function(d) { return x(d[0]) - .5; })
  23. .attr("y",function(d) { return y(d[1]); })
  24. .attr("width",5)
  25. .attr("height",function(d) { return height - y(d[1]); })
  26. .style(style);
  27.  
  28. vis.select(".x.axis").call(xAxis);
  29. vis.select(".y.axis").call(yAxis);
  30. };
  31.  
  32. svg.attr("width",width + margin.left + margin.right)
  33. .attr("height",height + margin.top + margin.bottom);
  34.  
  35. vis.append("g")
  36. .attr("class","x axis")
  37. .attr("transform","translate(0," + height + ")")
  38. .style({ 'stroke': 'Black','fill': 'none','stroke-width': '3px'})
  39. .call(xAxis);
  40.  
  41. vis.append("g")
  42. .attr("class","y axis")
  43. .style({ 'stroke': 'Black','stroke-width': '3px'})
  44. .call(yAxis);
  45.  
  46. // now we draw the first barchart (we do not know about the 2nd one yet)
  47. var data1 = [[2,0.5],[4,0.8],[6,0.6],[8,0.7],[12,0.8]];
  48. x.domain([0,13]);
  49. y.domain([0.9,0]);
  50.  
  51. vis.append("g")
  52. .attr("class","bar1");
  53.  
  54. vis.select(".bar1")
  55. .call(redraw,data1,{'fill': 'Red','stroke': 'Black'});
  56. </script>

解决方法

我建立在解释的答案,并更有选择地应用了行程宽度.这是我最终结论:
  1. vis.selectAll('.axis line,.axis path')
  2. .style({'stroke': 'Black','stroke-width': '3px'});

猜你在找的JavaScript相关文章