How to customize the color scale in a D3 line chart?

后端 未结 2 1344
耶瑟儿~
耶瑟儿~ 2020-12-04 22:23

How do I change the color of lines in a d3 line chart, for example in Mike Bostock\'s multi-series D3 line chart.

In his example chart, Mike Bostock uses D3\'s built

相关标签:
2条回答
  • 2020-12-04 22:53

    for D3 v4

       let color = d3.scaleOrdinal()
          .domain(["New York", "San Francisco", "Austin"])
          .range(["#FF0000", "#009933" , "#0000FF"]);
    
    0 讨论(0)
  • 2020-12-04 23:20

    You're only missing the square brackets around the values in .range() -- it takes an array as argument. So the code should be

    var color = d3.scaleOrdinal() // D3 Version 4
      .domain(["New York", "San Francisco", "Austin"])
      .range(["#FF0000", "#009933" , "#0000FF"]);
    

    Complete example here.

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