Line chart not hitting the right value on chart and has a smooth line

前端 未结 2 1172
说谎
说谎 2021-01-24 09:48

Below is my line graph where I am using 2 lines to show different values,

One line is blue and the other is red.

I want the line to have sharp points. and i woul

相关标签:
2条回答
  • 2021-01-24 10:14

    If you don't want d3 to smooth the edges, you should remove the interpolation from the line generator.

    https://jsfiddle.net/cexLbfnk/3/

    var valueline2 = d3.svg.line()
      .interpolate("basis") // this line needs to go
      .x(function(d) {
        return x(d.date);
      })
      .y(function(d) {
        return y(d.JANSALES);
      });
    
    0 讨论(0)
  • 2021-01-24 10:29

    Just remove the interpolate function here:

    var valueline = d3.svg.line()
        .interpolate("basis")
        .x(function(d) {
            return x(d.date);
        })
        .y(function(d) {
            return y(d.XMAS);
        });
    

    And do the same in valueline2. Right now you're using basis, which creates a B-spline.

    In case you want to set a different interpolation, here is a list of available options in D3 v3.x.

    Here is your updated fiddle: https://jsfiddle.net/7apnhbqd/

    0 讨论(0)
提交回复
热议问题