Back to list
Views:   0
Replies:  0
Archived

,
Reply 1
Some indirect inputs that may be useful


Basically a chart is composed of
 -  An X- axis
 -  A Y- axis
 -  Or No Axis (Pie chart and others)
 -   Has a Title
 -   Has Legends
 -   Different renderings (bar, column, pie, candle-stick etc).
 -   Has model or data to bind to
 -   et el

If you analyze this you may observe that the only changing part in this is the rendering, i.e. a line chart, a pie chart etc rest other things are composable or in other words you may thing it this way...

A chart  has
-   a data to bind to
-   Render as

And is decorated with a 
- Title
- Axis
- Legends 
etc.


So, you can create various decorators for these elements and compose your main chart with these decorators at runtime and as and when required.

Approach 1 - Decorator pattern

The higher level API could be something like this

// Create a chart with legends
Chart lineChart = new LineChart();
ln.DataSource =  "Your datasource here";
lineChart.Render();   // Renders the linechart without legend

LegendsChart  ln = new LegendsChart(lineChart);

ln.Render();   // Renders the line chart with legends as well

Refer Decorator patterns here  http://www.dofactory.com/Patterns/PatternDecorator.aspx
You can add more decorators as needed without modifying your existing code


Approach 2 - Fluent API
It will look something like this
Chart lineChart  = new Linechart().ShowLegend();
linChartDataSource = "Your datasource here";
lineChart.Render();

lineChart.AddBorder();
lineChart.Render();

A good example of fluent interface can be found here.. http://weblogs.asp.net/jgalloway/archive/2006/12/06/a-simple-example-of-a-fluent-interface.aspx



NOTE:  This is just couple of  approaches, you an find numerous other approaches as well
 
Rajesh Pillai, Nov 21, 2011


Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas