Skip to content

Commit

Permalink
Add providers support
Browse files Browse the repository at this point in the history
  • Loading branch information
Natim committed Jun 11, 2013
1 parent 2ad7711 commit 7a18a30
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions chartjs/views/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@


class BaseLineChartView(JSONView):
providers = {}

def get_context_data(self):
data = {}
data['labels'] = self.get_labels()
Expand All @@ -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):
Expand All @@ -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 []

0 comments on commit 7a18a30

Please sign in to comment.