简体   繁体   English

Django应用中Highcharts图中的X轴标签

[英]X axis label in Highcharts graph in Django app

I have created Highcharts graph by this code: 我通过以下代码创建了Highcharts图:

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 ? 如何添加X轴标签,使其显示月份名称而不是0和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}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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