Display COVID-19 data for US states in C#


The example Graph world total COVID-19 cases, deaths, and recoveries in C# lets you view and compare COVID-19 data for countries around the world. This example lets you compare data for the US states and territories.

I asked in previous posts for people to let me know if they found time-sequence data for the states, and Adam Kelly did on The COVID Tracking Project.

Not surprisingly their data is not in the exact same format as the data used by my earlier examples, so this example needs to load and process its data differently. The same basic technique or loading the data in a CSV file still works, however, so I won’t describe the process here in detail.

I also don’t have time right now to explain how this program works in detail. Even worse, I have not had time to thoroughly test the program so it may contain more than my usual number of bugs. 😉 If you find a bug, please note it in the comments below.

The program downloads its data from this URL: https://covidtracking.com/api/v1/states/daily.csv. Like the previous programs, it saves today’s data in a file named after the date (as in state_data2020_05_16.csv) and it doesn’t download the data if a file with that name already exists.

This program is different from the earlier ones because it lets you display multiple kinds of data simultaneously. For example, it lets you display the number of positive and negative test results at the same time. For example, the following picture shows positive (bottom) and negative (top) tests for New York.


Notice how the negative tests curve is slightly upward curving. That indicates that New York is continuing to expand testing, producing a greater number of tests each day.

Also notice that the positive tests curve is downward curving, showing that New York is recording a smaller number of new COVID-19 cases each day. The two curves together are a sign that New York is starting to stabilize.

This picture also shows an artifact of the data. Notice that the top curve ends with a small horizontal section. That could be due to the last two days having exactly the same values, but it may also be due to the fact that the data has not been updated for the last day. I would not assume that the curve is actually flat, particularly if the rest of the curve does not seem to be approaching horizontal.

Note also that the data may be spotty or unreliable. In fact, the CSV file containing the data even has a dataQualityGrade column that indicates the quality of the data for each row. The example program does not do anything with those values, but you might want to look at them if you find a result that you want to study more closely.

Right now it looks like the only states where the number of confirmed cases is starting to slow are VT, AK, HI, MT, NJ, and NY. The following picture shows the numbers of confirmed COVID-19 cases per million in those states except NY and NJ. (Those two states have had so many cases that including them skews the scale so much that you can’t really see the others.)


Most of the other states don’t look like their curves are leveling out. For example, the following picture shows the number of confirmed COVID-19 cases per million for WI, one of the states that has been most vocal about loosening restrictions.


You can use the example program to see how different states are doing.

One topic that I also think interesting is how the numbers of cases or fatalities relates to the restrictions in place in each state. For example, Hawaii has tight restrictions and an extremely low case rate. In contrast, Indiana has relatively loose restrictions and a much higher death rate.

The web site WalletHub posted the following picture showing ranking of state restriction level plotted against deaths.


You can go to this WalletHub page to see the actual chart, which is interactive and has tooltips.

Some parts of the picture make sense. I suspect the states in the upper right corner, such as NY and NJ, are there because they got hit hard early on and then introduced strict restrictions to fight their ongoing emergencies.

Hawaii’s position is also understandable. They have some very tight restrictions and very few deaths.

I might guess that some of the states closer to the lower left corner are there because of geography. For example, MT and UT are less densely populated than many other states so the coronavirus may not spread as quickly there. Similarly AK and WY are sparsely populated and they, too, have relatively low death rates.

I would like to see a version of the WalletHub plot with deaths per million rather than “Death Rate Ranking.” If the ranking simply means which country is best, second best, etc., then we might be able to learn a bit more by plotting actual death rates. For example, on the plot PA and NY are so close that they touch, but their numbers of deaths per million are very different with 1,147 deaths per million in NY and 339 deaths per million in PA. Maybe I’ll try to build a program that makes this comparison when I have time.

Meanwhile, download the example, experiment with it, and post any interesting findings in the comments below.

Download Example   Follow me on Twitter   RSS feed   Donate

About RodStephens

Rod Stephens is a software consultant and author who has written more than 30 books and 250 magazine articles covering C#, Visual Basic, Visual Basic for Applications, Delphi, and Java.
This entry was posted in drawing, graphics and tagged , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.