Skip to content

Instantly share code, notes, and snippets.

@kristjan-eljand
Created May 25, 2022 09:11
Show Gist options
  • Save kristjan-eljand/03955447c4147d23dc0c91c1ddeefd1b to your computer and use it in GitHub Desktop.
Save kristjan-eljand/03955447c4147d23dc0c91c1ddeefd1b to your computer and use it in GitHub Desktop.
Create plot with plotly.js and the data is provided by the Flask back-end
<!--
============================================================
Plotly.js barchart
============================================================
-->
<div class="row">
<div class="col-lg-4" style="outline:1px solid black;">
<strong>Day-ahead prices</strong>
<div id="chart" class="container col-12"></div>
</div>
</div>
<script src='https://cdn.plot.ly/plotly-latest.min.js'></script>
<script type='text/javascript'>
// Getting the data from Flask session
let x = {{session['da_dates']|safe}};
let y = {{session['da_prices']|safe}};
var trace1 = {
x: x,
y: y,
type: 'scatter',
line: {shape: 'hv'},
mode: 'lines',
name: 'Day-ahead prices',
marker: {
color: 'Black',
}
};
var data = [trace1];
var layout = {
//https://plotly.com/python/reference/layout/yaxis/
yaxis: {
showline: false,
showgrid: true,
showticklabels:false,
},
xaxis: {
ticklabeloverflow: "allow",
tickangle: 0,
dtick: 3,
tick0: 1,
},
plot_bgcolor: "rgba(0,0,0,0)",
margin: {
l:5,
r:30,
t:20,
b:30,
},
showlegend: false,
height: 250,
font: {
size:10,
},
hoverlabel: {
font: {
size:10,
},
}
};
var config = {
responsive: true,
displayModeBar: false,
}
Plotly.newPlot('chart', data, layout, config);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment