Well, I'm creating an "stats" website. Already have a template, little data and structure.
I like Google Charts API, specially the charts appearance, so I've created a HtmlHelper as an extension for it. You can uset just like this:
@Html.GoogleChart("Types", 300, 300, GChartType.Pie, (List<KeyValuePair<string, int>>)ViewBag.MyData)
It has several overloads and support multiple chart types and single/multidimension data. It returns the full html code for the chart image.
I will release the helper as Open Source in a few weeks, I'm just fixing some eventual bugs.
As you can see, I pass a List of KeyValuePair to the View through the ViewBag, so the chart can be generated using that data.
This works OK, but I'm facing multiple Controllers using the same data to generate charts and I want to code DRY. Can some of you, Jedi Masters help this young Padawan?
I think I have two problems:
- How to not repeate chart in the Views;
- How to not retrieve the stats/filtered data from the database in multiple controllers;
Facing this two problems, how to solve them?
- Create partial Views with the Chart Helper already set?
- Create a ChartController with Actions of each specific chart?
- Create a controller to retrieve data and organize it?
- Make a simple class to get data and return the organized data to multiple controllers?
- Make a class to return only the url of the charts insted of using the Helper?
- Both controller for charts and for data?
- Make Ajax calls to theese guys?
Can someone help me understand the possibilities and maybe show a path?
I appreciate your time spent here!