Пожалуйста, нужна помощь. У меня есть сценарий python, написанный отдельно в отдельном файле, который я использую для создания панели мониторинга. Теперь в моем интерфейсе панели инструментов есть диаграмма js и Iam new для диаграммы. js. Вот как мой сценарий построения python выглядит следующим образом:
import pandas as pd
import numpy as np
#rom plot_codes import dicharge_no
import plotly
import plotly.graph_objects as go
import plotly.express as px
from plotly.offline import plot
#Data function
def data_used():
# Import data
df = pd.read_csv("cap.csv", low_memory=False)
# get counts per NAR type
df_nar = pd.DataFrame(df.groupby('Hos_id')['Document Source'].value_counts())
df_nar = df_nar.rename({'Document Source': 'Doc count'}, axis='columns')
df_nar = df_nar.reset_index()
# set up plotly figure
fig = go.Figure()
# Manage NAR types (who knows, there may be more types with time?)
nars = df_nar['Document Source'].unique()
nars = nars.tolist()
nars.sort(reverse=False)
# add one trace per NAR type and show counts per hospital
data = []
for nar in nars:
# subset dataframe by NAR type
df_ply = df_nar[df_nar['Document Source'] == nar]
# chege
chart_data=df_ply.to_json()
return chart_data
Теперь этот сценарий в основном строит гистограмму, которую я ожидаю построить на переднем конце графика js
вот мой html интерфейс выглядит так:
<html>
<head>
<title>
Test plot graph with chart JS
</title>
<script type="text/javascript" src="/static/assets/Chart.min.js"></script>
<script type="text/javascript" src="/static/assets/jquery-3.3.1.min.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
</head>
<body>
<div class="bgc-white p-20 bd">
<h6 class="c-grey-900">Line Chart</h6>
<div class="mT-30" >
{{ doctors|safe }}
{{ chart_data|safe }}
<canvas id="neo_bar_graph"></canvas>
</div>
<script>
$(document).ready(function(){
var ctx = document.getElementById("neo_bar_graph").getContext('2d');
var neo_bar_graph = new Chart(ctx, {
type: 'bar',
data: {labels:
datasets:
{ chart_data|safe }}
})
});
</script>
</div>
</div>
</body>
</html>
Я не получаю никакого графика, есть кто-нибудь, кто пробовал python с диаграммой js и получил вывод? Пожалуйста, помогите мне получить вывод на переднем конце.