areski / django-nvd3

Django wrapper for nvd3 - It's time for beautiful charts
Other
416 stars 124 forks source link

line chart: explicility specify color #16

Closed ragrawal closed 10 years ago

ragrawal commented 10 years ago

Hi. Great work on creating this project. I was able to quickly get all my graphs generate. However I am not able to determine two things

  1. How can I explicitly colors for different lines in a line chart.
  2. Is there support for multichart. I want to draw three line on a same graph. But one of the line has a very different scale as compared to the other two and therefore I want to draw two y-axis and force this line to be on secondary y-axis. This is something possible using multiChart. But I wasn't able to find an example of that.

Thanks. Looking forward for a solution. Ritesh

areski commented 10 years ago
  1. Yes a color parameter called "color_list" can be passed to extra settings : https://github.com/areski/django-nvd3/blob/master/demoproject/demoproject/views.py#L66 You can see the code of python-nvd3 for more detail
  2. Yes you can look at this demo: https://github.com/areski/django-nvd3/blob/master/demoproject/demoproject/views.py#L275
zebulon2 commented 10 years ago

I do not think this is working, at least with anything else than pieChart. Actually, color_list has to be passed to extra_serie, not to extra. And even then, it does not work for lineChart. I will see if I can provide some patch for this.

However, there is a quick fix: in extra (not extra_serie), pass 'color_category':'category10' (or 20b, 20c, default is 20) to change the palette. This way, there is a better disctinction for lineCharts with only 2 or 3 series. The default (category20) works nicely for lineCharts with more than 6-8 series.

zebulon2 commented 10 years ago

There is also another way to make this work now that I have implemented the chart_attr attribute in extra: you may use now in extra: 'chart_attr': {'color':color_list,},

and declare your color_list somewhere in your code, e.g. color_list = ['orange', 'yellow', '#C5E946', '#95b43f', 'red', '#FF2259', '#F6A641']

This will override 'color_category' you may pass in extra.

areski commented 10 years ago

Please check this fix, it seems to work nicely for me: https://github.com/areski/django-nvd3/commit/3ce948794aab69d0c848b84feaa0f969ba6b696e

mGovan commented 10 years ago

Hey is it possible to get a similar example for discrete bar charts or multi-barcharts

JohnnyZ commented 10 years ago

I am not sure if pip is not finding a version to upgrade to, but my version installed is django-nvd3==0.6.0 and I am still having troubles changing the color of my lines. http://stackoverflow.com/questions/23202088/django-nvd3-cannot-change-line-color