Originally I had a basic line chart. I then tried to parse data into the js portion of the html using jinja but obviously that didn’t work. I then tried to parse directly into js. Unsuccessful. Now I tried using a json file and grabbing the values. Again Unsuccessful.
Currently trying to iterate over it and it’s not working
I tried parsing through js, unsuccessful, tried jinja, tried using a json file
fetch('Solo-Trade-Journal/monthly_data.json')
.then(response => response.json())
.then(data => {
// Parse the JSON data and extract the dates and growth values
var labels = data.map(item => item.date);
var growth = data.map(item => item.growth);
// Select the canvas element and create a new Chart object
var ctx = document.getElementById('myLineChart').getContext('2d');
var myLineChart = new Chart(ctx, {
type: 'line', // specify the chart type
data: {
labels: labels, // these labels appear on the x-axis
datasets: [{
label: 'My First Dataset', // the name of this dataset (optional)
data: growth, // the data points for this dataset
fill: false, // don't fill the area under the line
borderColor: 'rgb(75, 192, 192)', // the color of the line
tension: 0.1 // the smoothness of the line
}]
},
options: {
responsive: true, // make the chart responsive
}
});
});
# Iterating over data and extracting required information
monthly_list = []
for entry in data['data']:
data_info = {
'date': entry['date'],
'growth': entry['growth'],
}
monthly_list.append(data_info)
# Printing the list of data dictionaries
print("Data list:", monthly_list)
monthly_list_json = json.dumps(monthly_list)
# Writing the data to a JSON file
with open('monthly_data.json', 'w') as f:
f.write(monthly_list_json)
2