nvd3.js - unable to change color of line in line chart

隐身守侯 提交于 2020-01-03 15:31:50

问题


I am trying to change the colors of different lines of the nvd3 line chart here but am unable to understand how to do so. I would like to change the colors of the 2 lines in the example to green and cyan. I tried

nv.addGraph(function() {
   var chart = nv.models.lineChart()
      .useInteractiveGuideline(true)
      .color(["rgb(0,255,0)","rgb(255,165,0)"]);
}

It worked for scatter chart here. But the color does not change for line chart. Any suggestions.

Thanks


回答1:


You can use this!

return [
    {
      values: data,      //values - represents the array of {x,y} data points
      key: 'Money', //key  - the name of the series.
      color: '#33ccff'  //color - optional: choose your own line color.
    }
  ];



回答2:


In your CSS:

.nv-group.nv-series-0 {
    stroke-opacity: 1; 
    fill-opacity: 0.5; 
    fill: red; 
    stroke: red;
}

This will change the color for the first line to red, for example. Use .nv-group.nv-series-1 for second line, and so on...



来源:https://stackoverflow.com/questions/22993992/nvd3-js-unable-to-change-color-of-line-in-line-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!