score:1
like the error says, you can not iterate over a date
object, so for start_date in seven_days
will not work.
you can however use a for
loop here like:
for dt in range(7):
bookings.setdefault(today+datetime.timedelta(dt), 0)
a dictionary has a .setdefault(..)
function that allows you to set a value, given the key does not yet exists in the dicionary. this is thus shorter and more efficient than first checking if the key exists yourself since python does not have to perform two lookups.
edit: since python-3.7 dictionaries are ordered in insertion order (in the cpython version of python-3.6 that was already the case, but seen as an "implementation detail"). since python-3.7, you can thus sort the dictionaries with:
bookings = dict(sorted(bookings.items()))
prior to python-3.7, you can use an ordereddict
[python-doc]:
from collections import ordereddict
bookings = ordereddict(sorted(bookings.items()))
Source: stackoverflow.com
Related Query
- Django - update dictionary with missing date values, set to 0
- Update Chart JS with date range selector
- How to write better code in es6 for formatting an object with array values
- chartjs with the plugin chartjs-plugin-dragdata can i set fix dropdown values
- ChartJS - Graphic with multiple values on the same date
- Chart.js Update start date with button selector
- How to set data values as labels in Chart.js with a Radar Chart
- Dynamically update values of a chartjs chart
- Chart.js Bar graph with percentage values
- line chart with {x, y} point data displays only 2 values
- How to display inline values in a stacked bar chart with Chart.js?
- Chart.js Timeseries chart - formatting and missing data values
- dump missing date in data for chartjs
- scattered graph with xAxes of date react-chratjs-2
- Angular2 Update ng2-charts with labels
- Stepped line with null values in chart.js
- Is it possible to revert x-axe values in line chart with chart.js
- Live Update Callback -> afterTitle with Array via JSON file
- Chartsjs update datasets with dropdown
- Data with pair X and Y values
- How to set ticks on axes dynamically with chart.js?
- Chart.js two Y-Axis, one with negative values
- How to create dynamic charts with Django and Chart.js?
- how to hide 0 value on Yaxis in Chart.js with negative values
- Chart.js - custom tooltip with multiple values
- Dynamicly update scatter/line chart in Chart.JS with multiple x/y grids
- how to set color for each item in tooltip with ChartJS
- [Vue warn]: You may have an infinite update loop in watcher with expression "chartData"
- Chart.js - Draw charts with opposite bars - How to set both the y-axis ends to positive number?
- Chart Js update legend boxes of graph with graph line style
More Query from same tag
- How can i move a point through both x-axis and y-axis while the curve is not changed in a chart.js line graph?
- Updating a Pie Chart in React as Data is Entered
- Javascript function to check for missing dates on JSON object
- Chart JS horizontal bar chart width of bars and the chart
- The dataset in ng2 charts for bar graph is not setting properly
- ChartJS - How to add Text between Pie Chart and Legend
- Issue while plotting bar chart with custom x-axis with month and year in chart.js
- Using Chart.js with Dates as x-Axis labels
- Chart JS Layered Vertical Bar Chart
- chartjs height does not follow parent container
- How to add text to chart.js data?
- I have a issue with chart.js, php and infomix database?
- How to draw horizontal Lines using chart.js 3.x ? Cannot get it working
- ERROR : syntax error, unexpected '$app' (T_VARIABLE), expecting ')'
- How do I fix over limit y axis value in ChartJS
- Chart.js not displaying when including variable
- Can a service get access to component's template
- Django Multiple chartJs chats in a page
- Hide x-axis labels but show tooltips in chart.js
- How to create range based ticks in chart js? (like in attached image)
- Move y-Axis and hide in Chart.JS V3
- Chart js with problems when using too many series
- Uncaught Error: Can't resolve all parameters for Chart: (?, ?) in Ionic2
- Django Serializers - Return the sum of values by filter
- Getting clicked object from each section of a single stack bar as my stack bar has multiple sections Chart.js
- Chart.js plugin annotation line shadow
- How to group smaller Pie Chart slices together to Improve Readability in chartjs
- Chart.js "display:none" Issue
- GWT Chart.js implementation throws 'unable to get property 'insertBefore' of undefined or null reference
- Dynamically update the options of a chart in chartjs using Javascript