peopledoc / django-chartjs

Django Class Based Views to generate Ajax charts js parameters.
Other
404 stars 112 forks source link

Update lines.py #53

Closed edras closed 4 years ago

edras commented 4 years ago

I made a modification on the BaseLineChartView class. Instead of using the class BaseLineOptionsChartView, I added the method get_options(self, index, color) to BaseLineChartView By this way, it is possible to insert new options per dataset preserving the default ones at the client View class. Example as in the Readme:

class LineChartJSONView(BaseLineChartView): def get_labels(self): """Return 7 labels for the x-axis.""" return ["January", "February", "March", "April", "May", "June", "July"]

def get_providers(self):
    """Return names of datasets."""
    return ["Central", "Eastside", "Westside"]

def get_data(self):
    """Return 3 datasets to plot."""

    return [[75, 44, 92, 11, 44, 95, 35],
            [41, 92, 18, 3, 73, 87, 92],
            [87, 21, 94, 3, 90, 13, 65]]

def get_options(self, index, color):
    options = super(LineChartJSONView,self).get_options(index, color)
    options.update({'lineTension':0})
    return options

If one uses the BaseLineOptionsChartView, it is necessary to modify the html template to: type: 'line', data: data.data, options: data.options,

Using as I suggested, it is not needed to modify the chart.html javascript anymore, keeping it as the README file: type: 'line', data: data,

With this suggestion, event the BaseLineOptionsChartView is not necessary anymore.

Regards

Natim commented 4 years ago

@edras It seems that get_options and get_dataset_options are two different things. Would my review works for you?

edras commented 4 years ago

Yes, you are right, get_options and get_dataset_options are different things.

Am Mi., 6. Mai 2020 um 05:46 Uhr schrieb Rémy HUBSCHER < notifications@github.com>:

@edras https://github.com/edras It seems that get_options and get_dataset_options are two different things. Would my review works for you?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/peopledoc/django-chartjs/pull/53#issuecomment-624520383, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD2IQR2QZIVVOUW3SQABE3RQEPXZANCNFSM4MZ2XAPA .