Working with NetSpell and NPlot - Producing graphs from data sources
(Page 5 of 5 )
NPlot’s distribution includes a nice demo application that runs through many of NPlot’s chart types. The application demonstrates just how easy it is to feed data sources into a plot object and produce a detailed graph. Example 4-3 shows extracts from the demo app for creating a CandlePlot graph showing stock price data.
Example 4-3. Creating a CandlePlot from an XML file
// The plot surface to hold graphs. Note the surface is an
// NPlot.Windows.PlotSurface2D class instead of
// NPlot.PlotSurface2D. The utilized class derives from
// Forms.UserControl and automatically paints itself.
private NPlot.Windows.PlotSurface2D plotSurface;
// obtain stock information from XML file DataSet ds = new DataSet();
System.IO.Stream file = Assembly.GetExecutingAssembly().GetManifestResourceStream(
"NPlotDemo.resources.asx_jbh.xml" ); ds.ReadXml( file, System.Data.XmlReadMode.ReadSchema ); DataTable dt = ds.Tables[0];
// create CandlePlot
CandlePlot cp = new CandlePlot(); cp.DataSource = dt;
cp.AbscissaData = "Date";
cp.OpenData = "Open";
cp.LowData = "Low";
cp.HighData = "High";
cp.CloseData = "Close";
cp.BearishColor = Color.Red;
cp.BullishColor = Color.Green;
cp.StickWidth = 3;
cp.Color = Color.DarkBlue;
plotSurface.Add( new Grid() ); plotSurface.Add( cp );
plotSurface.Title = "AU:JBH"; plotSurface.XAxis1.Label = "Date / Time"; plotSurface.YAxis1.Label = "Price [$]";
plotSurface.Refresh();
An input record from the XML data file looks like this:
<asx_jbh>
<ID>1270061</ID>
<CompanyID>800</CompanyID>
<Date>2003-10-23T00:00:00.0000000+10:00</Date>
<Open>2.2</Open>
<Low>2.15</Low>
<High>2.27</High>
<Close>2.25</Close>
<Volume>28859100</Volume>
<AdjClose>2.25</AdjClose>
</asx_jbh>
Figure 4-21 shows the graph produced by this code and data.
NPlot offers great flexibility for combining plot types, too. Figure 4-22 shows the power of NPlot by layering multiple y-axes, a dashed-line plot, and a histogram plot.
Getting Support
Support for NPlot is limited to submitting bug reports at its home page.

Figure 4-21. CandlePlot generated from example code

Figure 4-22. A complex graph using multiple types
NPlot in a Nutshell
The current version of NPlot is 0.9.9.3—-it has not yet reached version 1.0. This reflects the following facts:
Some functionality that many users expect from a charting library is still missing.
NPlot is not yet considered basic-feature complete (though it is getting close).
The API is still subject to change without notice and without regard to backwardcompatibility.
The focus remains on creating the best library design possible.
There are no separate development/stable branches of the code. A given release of
NPlot may include both bug fixes and significant enhancements. The latter have
the potential to break functionality that worked in previous releases.
That said, NPlot is known to be used reliably in several production systems.
NPlot is an easy-to-use, flexible charting library that has a wide range of applications. It is under active development, with particular focus on polishing the interface and achieving a very stable release for version 1.0.
—Matt Howell, creator of NPlot
Please check back tomorrow for the continuation of this article.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
This article is excerpted from chapter four of the book Windows Developer Power Tools, written by James Avery and Jim Holmes (O'Reilly; ISBN: 0596527543). Check it out today at your favorite bookstore. Buy this book now.
|
|