django controlcenter显示折线图,其中包含来自模型文件字段的多个项目

时间:2018-09-11 17:55:00

标签: django python-3.x control-center

我有一系列模型条目,其中包含存储在h5py文件中的pandas数据框。每个条目文件的结构如下:

index - date - rate - active

我想绘制其中每一个的费率列随时间(日期)的变化情况。所以我开始用django controlcenter创建以下LineChart类:

import datetime
from django.utils import timezone
from controlcenter import Dashboard, widgets
from .models import Currency
import pandas as pd

class CurrencyPriceLineChart(widgets.LineChart):
    title = 'Currency Price (EUR)'
    width = 3
    height = 550
    model = Currency
    the_data = model.objects.all()
    limit_to = None

    class Chartist:
        options={
            'axisX':{
                'labelOffset':{
                    'x':-24,
                    'y':0
                },
            },
            'chartPadding':{
                'top':24,
                'right':24,
            }
        }

    def legend(self):
        the_vals = [f.symbol for f in self.the_data]
        return the_vals

    def labels(self):
        today = timezone.now().date()
        labels = [(today-datetime.timedelta(days=x)).strftime('%d.%m')
                   for x in range(self.limit_to)]
        return labels

    def series(self): 
        series = []
        for sym in self.legend:
            item = self.values.get(sym,{})
            series.append([item.get(label,0) for label in self.labels])
        return series

    def values(self):
        queryset = []
        for currency in self.the_data:
            the_file = currency.historical_data.file
            df = pd.read_hdf('{}'.format(the_file),'Currency')
            queryset.append([df])
        return queryset

那里的基本文档:https://django-controlcenter.readthedocs.io/en/latest/examples.html#displaying-series-in-legend

令我有些困惑,因为问题是关于从条目文件中绘制数据。以下是我目前所获得的屏幕截图:

enter image description here

0 个答案:

没有答案