agiliq / django-graphos

Django charting made *really* easy.
http://agiliq.com/demo/graphos
BSD 2-Clause "Simplified" License
441 stars 98 forks source link

Morris Donut not supporting colors option? #105

Open woodmicha opened 7 years ago

woodmicha commented 7 years ago

I'm trying to get the donut to respond to colors via the code below without success:

class ThresholdFactorsView(BaseAthleteView): template_name = 'factors.html'

def get_context_data(self, **kwargs):
    context = super(ThresholdFactorsView, self).get_context_data(**kwargs)
    factors_list = self.client.get_threshold_factors()
    chart_data, chart_colors = self.build_feature_data(factors_list)
    threshold_data_source = SimpleDataSource(data=chart_data)
    threshold_factors_chart = DonutChart(data_source=threshold_data_source, options={'colors': chart_colors})
    context['factors_chart'] = threshold_factors_chart
    context['slug'] = 'factors'
    return context

def build_feature_data(self, factors_list):
    colors = []
    rval = [['label','value']]
    for row in factors_list:
        feature = row['feature']
        coef = row['coef']
        color = "#008000"
        if coef < 0:
            color = "#FF0000"
        rval.append([feature, abs(coef)])
        colors.append(color)
    return rval, colors

I have a fix for it if you'd like me to send it along...