I have a simple question that I am not able to solve no matter how hard I try:
When I keep var data outside the js function and replace Name, Duration, Color with random inputs, I get a pie chart. However, when I bring the var data
inside the else statement with values that are successfully fetched per the console, the pie chart goes hidden w/o any js error popping in the console.
PY:
@blueprint.route('/Pie', methods=['GET', 'POST']) #change it to calendar retrieve
def Pie():
return jsonify(color = colorID, Duration = Duration_List, Name= Names)
JS:
fetch("/Pie").then(response => response.json()).then(function (response) {
if (response == null) {
console.log("returned nothing");
} else {
console.log(response.Name);
console.log(response.Duration);
console.log(response.color);
Name = JSON.stringify(response.Name);
Duration = JSON.stringify(response.Duration);
Color = JSON.stringify(response.color);
var data = {
labels: Name,
datasets: [{
label: "Data",
fill: true,
backgroundColor: gradientStroke,
borderColor: Color,
borderWidth: 2,
borderDash: [],
borderDashOffset: 0.0,
pointBackgroundColor: '#d048b6',
pointBorderColor: 'rgba(255,255,255,0)',
pointHoverBackgroundColor: '#d048b6',
pointBorderWidth: 20,
pointHoverRadius: 4,
pointHoverBorderWidth: 15,
pointRadius: 4,
data: Duration
}]
};
var myChart = new Chart(ctx, {
type: 'doughnut',
data: data,
options: gradientChartOptionsConfigurationWithTooltipPurple
});