【问题标题】:D3 LineGraph Circles Remove Overlap && Sort datesD3 折线图圆圈删除重叠和排序日期
【发布时间】:2012-09-21 15:02:37
【问题描述】:

http://www.fabieno.com/conanbatt/index.html

圆圈是重叠的,因为它们有工具提示。这有点痛苦。如何修改它以停止重叠?

另外,如何将日期格式化为我希望看到的格式?例如垂直和 YYYY/dd/mm

https://github.com/FabienO/OpenKaya-1/tree/master/widgets/rank_graph

任何帮助将不胜感激。谢谢。

【问题讨论】:

    标签: d3.js geometry margin overlap linegraph


    【解决方案1】:

    关于重叠的圆圈 - 假设您希望它们在 X 轴上的位置准确地表示他们的游戏发生的时间 - 我认为您有两个选择。

    在chart.js中:

    1) 使图更宽:

    // line 101
    var w = $(that.html).parent().width() || 500; //Sometimes this is 0, dont know why.
    

    2) 使每个圆的半径变小。

    // line 120
    var pointRadius = 2;
    

    作为奖励,我建议为每个圆圈添加填充颜色:

    // line 244, replace circles.enter() with the following
    circles
        .enter()
            .append('svg:circle')
                .attr('class', 'data-point')
                .style('opacity', 1e-6)
                .attr('cx', function(d) { return x(d.date) })
                .attr('cy', function() { return y(0) })
                .attr('r', function() { return (data.length <= maxDataPointsForDots) ? pointRadius : 0 })
                // On hover, fill the circle
                .on('mouseover', function(d, i) {
                  circles.filter(function(p) {
                    return d === p;
                  })
                  .style('fill', 'steelblue');
                })
                // Clear the fill
                .on('mouseout', function(d, i) {
                  circles.filter(function(p) {
                    return d === p;
                  })
                  .style('fill', 'white');
                })
            .transition()
            .duration(transitionDuration)
                .style('opacity', 1)
                .attr('cx', function(d) { return x(d.date) })
                .attr('cy', function(d) { return y(d.value) });
    

    关于 X 轴标签的日期格式:

    // line ~124
    var xAxis = d3.svg.axis().scale(x).tickSize(h - margin * 2).tickPadding(10).ticks(7).tickFormat(d3.time.format('%Y/%d/%m'));
    

    旋转它们:

    // line ~151
    // x ticks and labels
    if (!xAxisGroup) {
        xAxisGroup = svg.append('svg:g')
            .attr('class', 'xTick')
            .call(xAxis);
        xAxisGroup.selectAll('text')
            .attr('transform', 'translate(-210, 140) rotate(-45)');
    }
    else {
        t.select('.xTick').call(xAxis);
    }
    

    我分叉了你的 repo 并打开了一个 pull 反对它,这样你就可以一次看到所有的变化:https://github.com/FabienO/OpenKaya-1/pull/1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-05
      • 1970-01-01
      相关资源
      最近更新 更多