私はダッシュ環境で水平棒グラフをプロットしようとしていますが、日や数字などの要素をプロットすることはできますが、正しい範囲を取得できません。順序の言い方では、開始日は正しいが、終了日は正しくない。ダッシュプロットフレームワークで日付プロットが破損しているようです
def build_data(contract_name, stream): # one stream only
data = []
month_list = sorted([z['month'] for z in stream['monthList']])
month_list = [datetime.datetime.strptime(month, '%Y-%m-%d') for month in month_list]
print month_list
min_month = min(month_list)
max_month = max(month_list)
start = go.Bar(x=[min_month], y=[contract_name], orientation = 'h', marker=dict(color='rgba(1,1,1, 0.0)'))
end = go.Bar(x=[max_month], y=[contract_name], orientation = 'h', marker=dict(color='rgba(55, 128, 191, 0.7)',
line=dict(color='rgba(55, 128, 191, 1.0)', width=2,)))
data.append(start)
data.append(end)
return data
def plot_bar(data):
app.layout = html.Div(children=[html.H1(children=''), html.Div(children='''History.'''),
dcc.Graph(
figure=go.Figure(
data = data,
layout=go.Layout(title='', showlegend=False, barmode='stack', margin=go.Margin(l=200, r=0, t=40, b=20))),
style={'height': 300},
id='my-graph')
])
if __name__ == '__main__':
data = build_data('xxx', example_stream)
plot_bar(data)
print data
app.run_server(debug=True)
と入力データ:
example_stream={'status': 'active', 'monthList': [{'month': '2017-04-01'}, {'month': '2017-06-01'}]}
最も重要な側面は、2つの日付があります:「2017年5月1日」と「2017年4月1日には」Pythonの日付オブジェクトに変換しました。しかし、下限はプロットされていますが、エンディングバーは将来のある時点で終了します。
これらのルーチンを非日付データでチェックし、期待どおりに動作しました。
私は下にここにグラフを置く:おそらく二日はtimedelataではなく、日時でなければなりません
**アイテムの重量中心とアイテムの位置間のリンクは相対的なものではありません!**すべての位置は絶対値でなければなりません。アイテム/ステージの寸法だけが動的になります。もう一つのポイントは 'canvas.js'です。 – dsgdfg
@dsgdfgはい、両方とも日付データが絶対日付です。日付間の相対性はありません。 – disruptive
"stream"コンテンツdictまたは少なくとも "stream ['monthList']"コンテンツを示すコメントでコードを更新してください。ありがとう –