因此,我尝试使用 Django 中的 Highcharts 制作烛台图,但无法在网页上显示图表,而是显示所获取数据的 JSON 列表。
我正在使用 iexcloud 的 API 来获取历史数据
这是我的逻辑: 视图.py 文件:
def candlestick_chart_data(request):
api_key = 'my_api_key'
stock_data = get_historical_data(
"AAPL", start="2023-01-01", end="2023-05-05", output_format="pandas", token=api_key)
stock_data_array = [{
'x': date.isoformat(),
'open': row['open'],
'high': row['high'],
'low': row['low'],
'close': row['close']
} for date, row in stock_data.iterrows()]
return JsonResponse(stock_data_array, safe=False)
我的模板,即candlestick_chart.html
{% extends 'base.html' %}
{% block content %}
{% block home_css %}
{% endblock %}
{% endblock %}
以及我的 url 路径(如果需要):
path('candlestick-chart-data/', views.candlestick_chart_data, name='candlestick-chart'),
这是我在网页上得到的输出 本地主机网页图像
我尝试将 console.log 语句放入代码中,尝试在终端中打印数据,一切正常,但我无法理解为什么如果一切正常,图表不会出现在网页中
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号