我已经成功地使用flask,jinja和plotly-python绘制了图形 现在我想将该图导出到图像并设置为img元素,但是导出的图像显示没有任何数据的空图
已经尝试将jinja放入jquery中,但显示错误
<!doctype html>
<html>
<head>
<script type="text/javascript">
$(document).ready(function(){
console.log("ready");
var graphDiv=$("#chart");
$("#ExportButton").click(function(){
var d3 = Plotly.d3;
var img_jpg= d3.select('#jpg-export');
Plotly.toImage(graphDiv, {format: 'png', width: 800, height: 600}).then(function(url) {
// use the url
img_jpg.attr("src", url);
return Plotly.toImage(graphDiv,{format:'jpeg',height:400,width:400});
});
});
});
</script>
</head>
<body>
<div class="header">
<h2>
Plotly Chart Demo
</h2>
</div>
<div id="chart" class="chart">
{{mydiv|safe}}
</div>
<button id="ExportButton">Export</button>
<div id="dup" class="chart">
</div>
<img id="jpg-export"></img>
<!-- D3.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<!-- Plotly.js -->
在我的烧瓶应用程序中
@mod.route('/tryPlot')
def tryPlot():
topicId="23"
div=avg_sent_dateWise(str(topicId),"Topic No :"+topicId)
return render_template('tryPlot.html',mydiv=div)
Actual Output that I am getting
我希望图像中填充一些数据