diff --git a/chartjs/views/lines.py b/chartjs/views/lines.py index 943ad19..747d0df 100644 --- a/chartjs/views/lines.py +++ b/chartjs/views/lines.py @@ -5,6 +5,8 @@ class BaseLineChartView(JSONView): + providers = {} + def get_context_data(self): data = {} data['labels'] = self.get_labels() @@ -17,13 +19,19 @@ def get_colors(self): def get_datasets(self): datasets = [] color_generator = self.get_colors() - for data in self.get_data(): + data = self.get_data() + providers = self.get_providers() + num = len(providers) + for i, data in enumerate(self.get_data()): color = tuple(next(color_generator)) - datasets.append({'fillColor': "rgba(%d, %d, %d, 0.5)" % color, - 'strokeColor': "rgba(%d, %d, %d, 1)" % color, - 'pointColor': "rgba(%d, %d, %d, 1)" % color, - 'pointStrokeColor': "#fff", - 'data': data}) + dataset = {'fillColor': "rgba(%d, %d, %d, 0.5)" % color, + 'strokeColor': "rgba(%d, %d, %d, 1)" % color, + 'pointColor': "rgba(%d, %d, %d, 1)" % color, + 'pointStrokeColor': "#fff", + 'data': data} + if i < num: + dataset['name'] = providers[i] + datasets.append(dataset) return datasets def get_labels(self): @@ -35,3 +43,6 @@ def get_data(self): raise NotImplementedError( 'You should return a data list list. ' '(i.e: [[25, 34, 0, 1, 50], ...]).') + + def get_providers(self): + return []