Posts tagged RIA
Open Flash Chart in ASP.NET MVC
10If you’ve ever developed an application of any type, you know that the business function of that application is only half the story. Most business applications also have to take into mind that your business user is going to want reporting. As a developer I find reporting the most boring part of the development process, but it is becoming less and less painful for me as a developer to implement it into my applications. Within the last year Microsoft has released a charting addition to the .Net framework based on the Dundas charts package, but they only output static images. In most cases this is ok, but it doesn’t make for a very compelling experience. Open Flash Chart is one alternative to the .Net charting; it is interactive and dynamic, which can help you build those compelling interfaces that your clients look for. So the point of this walkthrough is to show you how to implement Open Flash Chart into your MVC application.
Step 1 – Download the Open Flash Chart package
Obviously you’ll need Open Flash Chart, you can download it from the Official Open Flash Chart. When you download it there is going to be a lot of files, but don’t worry about it I’ll tell you which ones you need.
Step 2 – Import The Files You Need
You are going to need two files at a minimum. There is a .Net library in the package but I’ll show you, you don’t need it. The first file is the open-flash-chart.swf. This file is the major component of the open flash chart package. I transferred this file directly into my content folder in my ASP.NET MVC project.
The next file you’ll need is the swfobject.js file, this will make placing your charts on the page much cleaner and simpler. Transfer this file into your scripts folder.
Step 3 – Integrating Open Flash Chart into your View
There are a couple things that I do to get Open Flash Chart into my view. I first modify my master page and add a new ContentPlaceHolder called “Scripts”. This allows me to inject custom scripts per view if necessary. My head tag in the master page looks like the following.
<head runat="server">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<link href="/Content/Site.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/swfobject.js" type="text/javascript"></script>
<asp:ContentPlaceHolder ID="Scripts" runat="server" />
</head>
The next step is to inject the Chart into the page. The following code does that.
<asp:Content ContentPlaceHolderID="Scripts" runat="server">
<script type="text/javascript">
swfobject.embedSWF(
"/Content/open-flash-chart.swf", "my_chart", "550", "200",
"9.0.0", "expressInstall.swf",
{ "data-file": "Home/GetData" }
);
</script>
</asp:Content>
Notice what is done here. You first point to the open-flash-chart.swf in your content folder. Next you specify the div you would like to inject the chart into. Thirdly, you specify the size. Right after that is about the flash version and the install if your client is missing flash on their machine. Lastly, the most important thing, the location of your data. Notice that it points to a controller action. I’ll show you how to code that next.
Step 4 – Data, Data, Data
A chart wouldn’t be a chart without data. This is where we will leverage the power of the newest .Net frameworks with anonymous types. Open Flash Chart uses JSON objects to create you chart, but we don’t want to spend hours creating a library or adding references to assemblies we don’t need. So I went ahead and created an action relating to the one seen above. The code looks like this.
public JsonResult GetData()
{
var data = new
{
title = new { text = "Many data lines", style = "{font-size: 20px; color:#0000ff; font-family: Verdana; text-align: center;}" },
y_legend = new { text = "Open Flash Chart", style = "{color: #736AFF; font-size: 12px;}" },
elements = new object[] {
new { type = "bar", alpha = 0.5, colour = "#9933CC", text = "Page views", values = new [] {9,6,7,9,5,7,6,9,7}},
new { type = "bar", alpha = 0.5, colour = "#CC9933", text = "Page views 2", values = new [] {6,7,9,5,7,6,9,7,3}}
},
x_axis = new { stroke = 1, tick_height = 10, colour = "#d000d0", grid_colour = "#00ff00",
labels = new {
labels = new[] { "January", "February", "March", "April", "May", "June", "July", "August", "Spetember" }
}
},
y_axis = new { stroke = 4, tick_length = 3, colour = "#d000d0", grid_colour = "#00ff00", offset = 0, max = 20 }
};
var result = Json(data);
// Allow Open Flash Chart to
// make request for data through GET
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return result;
}
There are two catches here. The first catch is that Open Flash Chart has some properties that have a dash in them, like “font-size”. The other problem is that Open Flash Chart does a GET Request for all data, that is why I have the funky code at the bottom of the action. Don’t forget to look at the Open Flash Chart documentation to get an idea of what you need to get your chart looking like you want it to.
Conclusion
So there you have it. Now you have integrated Open Flash Chart with the addition of two files and a new action. I love how easy it is to use this project in an Asp.net application. Look into the Open Flash Chart package, because I’m sure there are more and better ways to implement this charting package into your applications.
Jumping Development Niches – Realizing Learning
0.Net is one of those great platforms that gives you so much value without having to re-learn everything. I recently decided to jump back into Windows Presentation Foundation, to keep my skills there sharp. What I was surprised to find is that it is evolving at break neck speeds, almost to the point of giving me migraines. Obviously Microsoft isn’t moving at this speed to overwhelm developers, but instead to give value to those developer niches. About 5 – 10 years ago Microsoft thought of a developer as a windows developer, creating applications solely for use on their platform. Everything Microsoft made was centered around rapid application development or drag and drop development. This is clearly evident when you look at Asp.Net Web Forms. Since that time the world has evolved, and so has Microsoft’s view of those developers.
Microsoft is developing niches, and although they don’t mind you jumping around from niche to niche, they want to make sure to help those loyal to those niches by continually providing new value in shorter release iterations. This can make it tough, but not impossible, to catch up in a niche like WPF or Silverlight development. So what are these niches? Well they aren’t officially defined, but there are strong lines. There is obviously some overlap, so you might see some things repeated.
.Net Niches
- Web Development
- ASP.NET MVC
- ASP.NET Web Forms
- Windows Communication Foundation (WCF)
- Cloud Computing (Windows Azure)
- Windows Applications
- Windows Forms
- WPF
- Silverlight
- Rich Internet Applications (RIA)
- Silverlight
- Enterprise Systems
- Windows Workflow Foundation
- Office Development
- Cloud Computing (Windows Azure)
- SharePoint
- Reporting
- Simulation and Games
- XNA Framework
- Microsoft Simulators
- Robotics
These are the major niches as identified by Aqua Bird Consulting. I’m sure there are smaller niches that we’ve missed, but these are the ones that the majority of developers are involved in. So the question is, can you get one developer to know all this stuff off the top of their heads? No, of course not, these frameworks are dynamic and with shorter and shorter release cycles it would be a 24 hour a day job learning it all. So what can a developer do?
I’m No Tabula Rasa
This sadly is what some developers do, they throw up their arms and say they don’t need to learn that new stuff. They believe that Microsoft writes everything sub-standard and that they know better. This usually means these developers are entrenched in building new frameworks and systems and not leveraging the work of external developers. Building frameworks is great for developers because they get to nerd out, but terrible for the business (unless the business intends to sell this framework, but you’ll find few willing to buy). A business needs to perform its business functionality, and the longer a developer can’t provide that the longer the business losses critical revenue.
Jack of All Trades, Master of None
The second approach is to learn a little about every topic and know that it exists. In fears of sounding like a G.I. Joe public service announcement, “knowing is half the battle!” If you know something exists, you won’t spend weeks or months home rolling your own solution. This can be critical to saving time and money. The best place to start is Microsoft Developer Network (MSDN). This approach requires a lot of time surfing the internet and reading blogs. With this approach, when presented with a project, you can make the best decision about what technologies to use and learn more about it during the process of development. This approach has its ups and downs, but can help make sure that your solution is on the latest platform.
Bring in the Specialist
Pick two or three technologies and go deep. Learn everything about these few technologies and be able to talk critically and intelligently about them. This approach can work well for developers when they know what is expected of them. If you are a web developer, then you probably don’t need to read about XNA for your job (although you could read about the XNA framework for fun). This can be a double edged sword for the obvious reason that the only thing that never changes is that everything changes. Your company might be entrenched in web development one year, but decide to go into game development the next year; your skills don’t fit the job description anymore (nothing that drastic will probably happen, just making a point).
Conclusion
Doctors have used a similar approach in their profession. You will first go see a family doctor and he will attempt to diagnose your problem and treat it. If he has diagnosed your problem but cannot treat it, he then goes ahead and refers you to a specialist. Microsoft .Net is growing, both in depth and width. You can either go shallow and wide or deep and slim. You, as a developer know what’s best for you. Also you as a business owner, if you are one, know what you want your developers to be. Keep in mind that it is never too late to jump from one niche to another, but to be effective in any niche you need to do your time and pay your dues; these dues come in the form of long hours reading, learning, and doing.
