Last time we learned how to create a dynamic bar chart with data that we had to type in manually. That data entry part was tedious and unnecessary. Today we will solve that problem by creating a model that can load and parse data from an external file. Although in this example we only use the model to parse comma delimited file (CSV), we will build it in a way that allow us to parse tab delimited file as well. CSV is a very popular and compact format for storing data. It is also very easy to parse.
In this second tutorial on MVC we will learn how to create a simple bar chart view. We will also cover a new concept called composite view. It is an important concept in the MVC world that allows a view to contain other views. It will let you build complex views out of small interchangeable pieces. When your application grows, it is crucial to write code that is reusable, so your application remains maintainable. Breaking views into small reusable chunks of code is one way to do that. Below is the result of what we are going to build in this tutorial.
The chart shows monthly unemployment rate since 2005 from the U.S. Bureau of Labor Statistics.
For the last few years MVC frameworks have become a hot topic in the developer community. Many people love them and for a good reason. They make writing code much easier and more fun to do. The programs written in MVC are more scalable and easier to maintain. One of the biggest benefits is that if you learn one, you can probably learn others pretty quickly.
A few words about my background
I am a web developer and designer who specializes in data visualization. I have been using a few MVC frameworks such as Django, ASP.NET MVC and more recently iPhone SDK for my work and I can tell you, they are very similar. Since I am still learning these concepts myself, please let me know if I don’t make sense or I am completely wrong. I promise I won’t feel bad about it .
In this series of tutorials I will introduce you to the MVC world. You will learn how to make your code cleaner and your applications more modular. Along the way you will learn a few useful design patterns, one of which is MVC, and how to apply them to your work. Although the main focus is on building a data visualization framework, many techniques are applicable to any kind of work.