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

我不使用css,因为我想保存并处理创建的SVG可视化文件.这意味着我需要使用内联样式.到目前为止,我经历了d3,因为很有可能我做错了事情.

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

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

这是我的代码:

<script>
    var margin = {top: 20,right: 10,bottom: 20,left: 40};
    var width = 960 - margin.left - margin.right;
    var height = 100 - margin.top - margin.bottom;

    var x = d3.scale.linear().range([0,width]);
    var y = d3.scale.linear().range([0,height]);
    var xAxis = d3.svg.axis().scale(x).orient("bottom");
          // .tickFormat(d3.time.format("%H:%M"));
    var yAxis = d3.svg.axis().scale(y).orient("left").ticks(height/10);

    var svg = d3.select("svg");
    var vis = svg.append("g")
        .attr("transform","translate(" + margin.left + "," + margin.top + ")")
        .style({'font-size': '10px','font-family': 'sans-serif','font-style': 'normal','font-variant': 'normal','font-weight': 'normal'});

    var redraw = function(selection,data,style) {
        selection.selectAll(".bar")
            .data(data)
          .enter().append("rect")
            .attr('class',"bar")
            .attr("x",function(d) { return x(d[0]) - .5; })
            .attr("y",function(d) { return y(d[1]); })
            .attr("width",5)
            .attr("height",function(d) { return height - y(d[1]);  })
            .style(style);

        vis.select(".x.axis").call(xAxis);
        vis.select(".y.axis").call(yAxis);
    };

    svg.attr("width",width + margin.left + margin.right)
        .attr("height",height + margin.top + margin.bottom);

    vis.append("g")
      .attr("class","x axis")
      .attr("transform","translate(0," + height + ")")
      .style({ 'stroke': 'Black','fill': 'none','stroke-width': '3px'})
      .call(xAxis);

    vis.append("g")
      .attr("class","y axis")
      .style({ 'stroke': 'Black','stroke-width': '3px'})
      .call(yAxis);

    // now we draw the first barchart (we do not know about the 2nd one yet)
    var data1 = [[2,0.5],[4,0.8],[6,0.6],[8,0.7],[12,0.8]];
    x.domain([0,13]);
    y.domain([0.9,0]);

    vis.append("g")
      .attr("class","bar1");

    vis.select(".bar1")
      .call(redraw,data1,{'fill': 'Red','stroke': 'Black'});
</script>

解决方法

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


kindeditor4.x代码高亮功能默认使用的是prettify插件,prettify是Google提供的一款源代码语法高亮着色器,它提供一种简单的形式来着色HTML页面上的程序代码,实现方式如下: 首先在编辑器里面插入javascript代码: 确定后会在编辑器插入这样的代码: <pre
这一篇我将介绍如何让kindeditor4.x整合SyntaxHighlighter代码高亮,因为SyntaxHighlighter的应用非常广泛,所以将kindeditor默认的prettify替换为SyntaxHighlighter代码高亮插件 上一篇“让kindeditor显示高亮代码”中已经
js如何实现弹出form提交表单?(图文+视频)
js怎么获取复选框选中的值
js如何实现倒计时跳转页面
如何用js控制图片放大缩小
JS怎么获取当前时间戳
JS如何判断对象是否为数组
JS怎么获取图片当前宽高
JS对象如何转为json格式字符串
JS怎么获取图片原始宽高
怎么在click事件中调用多个js函数
js如何往数组中添加新元素
js如何拆分字符串
JS怎么对数组内元素进行求和
JS如何判断屏幕大小
js怎么解析json数据
js如何实时获取浏览器窗口大小
原生JS实现别踩白块小游戏(五)
原生JS实现别踩白块小游戏(一)