Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Highcharts label and sorting x-axis using Django-chartit

I have a problem using django-charit in which it utilizes Highcharts. So far, here is my code:

#creating chart
    ds = DataPool(
        series=
        [{'options': {
            'source': DataForecast.objects.all().order_by('id')},
          'terms': [
              'date_time',
              'wl_observed_m',
              'wl_forecasted_m']}
        ])

    cht = Chart(
        datasource=ds,
        series_options=
        [{'options': {
            'type': 'line',
            'stacking': False},
          'terms': {
              'date_time': [
                  'wl_observed_m',
                  'wl_forecasted_m']
          }}],
        chart_options=
        {'title': {
            'text': 'Forecast for January 19, 2014 2:00 PM'},
         'xAxis': {
             'title': {
                 'text': 'Date & Time'}},
         'yAxis': {
             'title': {
                 'text': 'Water Level, m.'}},
         'credits': {
             'enabled': False}})

The output of that is this: enter image description here

So, how do I change the label(encircled)? and sort the x-axis. I tried it by the query but no success.

like image 942
Sachi Tekina Avatar asked Dec 28 '25 18:12

Sachi Tekina


1 Answers

SORT : DataForecast.objects.all().order_by('id') sort query with .latest() or .order_by('-date') or by the datefield (the one you print to chart) instead of id.

like image 120
Ohad the Lad Avatar answered Dec 31 '25 07:12

Ohad the Lad