Python 通过烧瓶处理海图
我正在做一个项目,扫描一个网站,保存一些信息,并显示在一个图表 我使用Flask和ChartJS显示所有内容 基本上,我创建了一个名为Snapshot的类,它看起来像这样:Python 通过烧瓶处理海图,python,flask,Python,Flask,我正在做一个项目,扫描一个网站,保存一些信息,并显示在一个图表 我使用Flask和ChartJS显示所有内容 基本上,我创建了一个名为Snapshot的类,它看起来像这样: class Snapshot: list_1 = ['id1', 'id2', 'id3'] list_1_score = [ 10, 15, 20 ] timestamp = '19:50' 现在,我想在图表中显示的当然是我拍摄的这个网站的所有快照 不幸的是,ChartJS期望这种格式: data
class Snapshot:
list_1 = ['id1', 'id2', 'id3']
list_1_score = [ 10, 15, 20 ]
timestamp = '19:50'
现在,我想在图表中显示的当然是我拍摄的这个网站的所有快照
不幸的是,ChartJS期望这种格式:
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
label: 'My First dataset',
backgroundColor: window.chartColors.red,
borderColor: window.chartColors.red,
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor()
],
fill: false,
}, {
label: 'My Second dataset',
fill: false,
backgroundColor: window.chartColors.blue,
borderColor: window.chartColors.blue,
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor()
],
}]
}
这与我的“不兼容”。请记住,列表_1中的条目也可能消失
我使用的实际模板是
data: {
labels: {{timestamps|safe}},
datasets: [
{% for item in labels %}
{label: '{{item}}',
{{ dataset[loop.index0] }}
{% if loop.length != loop.index1 %}
,
{% endif %}
{% endfor %}
]
}
考虑到以下情况,我对如何生成数据集感到有点困惑:
1) ID可能会消失(内容已删除)
2) 可能会出现ID(内容刚刚添加)
当然,如果ID确实出现,它们应该从它们出现的快照的时间戳开始出现(我将如何做这样的事情?我是否用None
或什么填充数据部分?)