From: Dave C. <dav...@gm...> - 2009-09-18 15:13:11
|
I have two methods (which I see now could be simplified): protected void DrawIndicatorLineLeft(DataTable sourceDT, NPlot.Windows.PlotSurface2D plotSurface, string name, string abscissa, string ordinate, Color color) { LinePlot trendline = new LinePlot(); trendline.DataSource = sourceDT; trendline.AbscissaData = abscissa; trendline.OrdinateData = ordinate; trendline.Pen = new Pen(color, 1.0f); trendline.Label = name; PlotSurface2D.XAxisPosition xp = PlotSurface2D.XAxisPosition.Bottom; PlotSurface2D.YAxisPosition yp = PlotSurface2D.YAxisPosition.Left; plotSurface.Add(trendline, xp, yp); } protected void DrawIndicatorLineRight(DataTable sourceDT, NPlot.Windows.PlotSurface2D plotSurface, string name, string abscissa, string ordinate, Color color) { LinePlot trendline = new LinePlot(); trendline.DataSource = sourceDT; trendline.AbscissaData = abscissa; trendline.OrdinateData = ordinate; trendline.Pen = new Pen(color, 1.0f); trendline.Label = name; PlotSurface2D.XAxisPosition xp = PlotSurface2D.XAxisPosition.Bottom; PlotSurface2D.YAxisPosition yp = PlotSurface2D.YAxisPosition.Right; plotSurface.Add(trendline, xp, yp); } But you need to add an additional YAxis: protected NPlot.Windows.PlotSurface2D AddIndicator(DataTable dt, string name, string controlKey, string absiscca, string[] lineNames) { NPlot.Windows.PlotSurface2D indicatorPlot = this.plotSurface; indicatorPlot.YAxis2 = new LinearAxis(); indicatorPlot.YAxis2.TickTextNextToAxis = false; indicatorPlot.YAxis2.Label = name; indicatorPlot.YAxis2.LabelOffset = 30; indicatorPlot.YAxis2.LabelOffsetAbsolute = true; indicatorPlot.YAxis2.AutoScaleTicks = true; foreach (string lineName in lineNames) DrawIndicatorLineRight(dt, indicatorPlot, name, absiscca, lineName, Color.Red); indicatorPlot.Invalidate(); return indicatorPlot; } Here's a simple analytic I use: protected void DrawEMATrendLine(int maPeriods, Color color) { // generate the trendline DataTable dt = new DataTable(); Queue queue = new Queue(maPeriods); DataRow newDr; double ema = 0d; dt.Columns.Add("Date", typeof(DateTime)); dt.Columns.Add("EMA", typeof(double)); dt.Columns.Add("Sequence", typeof(int)); queue.Enqueue((double)this.dataTable.Rows[0][4]); foreach (DataRow dr in this.dataTable.Rows) { ema = Statistics.GetEMAMeanFromQueue(queue, (double)dr[4], maPeriods); newDr = dt.NewRow(); newDr[0] = dr[7]; newDr[1] = ema; newDr[2] = dr[8]; dt.Rows.Add(newDr); } DrawIndicatorLineLeft(dt, this.charts[hotChartIndex].PlotSurface, "EMA-" + maPeriods, "Sequence", "EMA", color); // You could use AddIndicator here } And two versions of the MA calc, one weighted and one EMA: public static double GetEMAMeanFromQueue(Queue queue) { double total = 0d; int counter = queue.Count - 1; int totalPeriods = 0; foreach (double d in queue) { total += Math.Abs(d * (queue.Count - counter)); counter--; totalPeriods += queue.Count - counter; } return total / (double)totalPeriods; } public static double GetEMAMeanFromQueue(Queue queue, double currentVal, int maPeriods) { /// ema% = 2/(queue.Count + 1) double emaExponent = 2d / (double)(maPeriods + 1); double yesterdaysEma = (double)queue.Dequeue(); double todaysEma = (currentVal * emaExponent) + (yesterdaysEma * (1 - emaExponent)); queue.Enqueue(todaysEma); return todaysEma; } The axis are easily the most complex part of nplot - and I still have trouble with them. It's too bad the original developers haven't take the time to create good examples of everything you can do with it. Or create docs that really explore it. But, once you get over the steep learning curve - it does work quite nicely. Dave Cline On Fri, Sep 18, 2009 at 7:46 AM, Thomas Erichsen <th...@th...> wrote: > Hey there, > > is there still anyone of the developers or advanced users around in this > mailing list? I am currently at a problem, that if I add two or more > linescans to a Plotsurface2D, only the last one is displayed. So, how > can I plot more than one XY-dataset? > > Any help or even a lifesignal is appreciated... > Thomas > > Thomas Erichsen schrieb: > > Dear all, > > > > in the example-section of nplot.com I found an example with multiple > > y-axes. I would like to do something similar (using nplot 0.9.10 stable > > in VB .Net), showing two sets of data with the same X-data, but > > different Y-Values and axes. > > > > Does anyone have some example sourcecode he could share? > > > > Thanks, > > Thomas > > > > > > -- > Dr. Thomas Erichsen > Keplerstr. 108 > 45147 Essen > > Tel.: +49 (0)162 9436314 > > > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry® Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9-12, 2009. Register now! > http://p.sf.net/sfu/devconf > _______________________________________________ > Nplot-devel mailing list > Npl...@li... > https://lists.sourceforge.net/lists/listinfo/nplot-devel > -- ___________________ Dav...@gm... Lake Oswego, OR 801-473-9213 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ |