简体   繁体   中英

X axis label in Highcharts graph in Django app

I have created Highcharts graph by this code:

def chart_data(request):

    dataset = DispatchPlan.objects.annotate(month=TruncMonth('scheduled_date')).values('month').annotate(
        c=Sum('weight')).values('month', 'c')

    chart = {
        'chart': {'type': 'column'},
        'title': {'text': 'Weight Dispatched by Months'},
        'series': [{
            'name': 'Months',
            'data': [{'name': row['month'], 'y': row["c"]} for row in dataset]
        }]
    }

    return JsonResponse(chart)

How can I add the X axis labels such that it shows month name instead of 0 and 1 ?

This is the one row of dataset from which the graph is plotted

{'month': datetime.datetime(2019, 6, 1, 0, 0, tzinfo=<DstTzInfo 'Asia/Kolkata' IST+5:30:00 STD>), 'c': 17600}

尝试像这样使用strftime文档 ):

{'month': datetime.datetime(2019, 6, 1, 0, 0, tzinfo=<DstTzInfo 'Asia/Kolkata' IST+5:30:00 STD>).strftime("%B"), 'c': 17600}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM