Esempio n. 1
0
            /// <summary>
            /// Generates the data to use in the plot line
            /// </summary>
            /// <param name="source"></param>
            public void Generate(DataChart <T> source)
            {
                this.Data = new DataTable();
                Data.Columns.Add(source.XAxis, source.getExpressionType(source.XAxis, source.XAxisGetValue));
                Data.Columns.Add(Expression, source.getExpressionType(Expression, GetValue));

                List <string> symbols = source.GetSymbolList(Symbol);

                foreach (var s in symbols)
                {
                    List <StockDataSet <T> > sources;
                    if (!source.DataSets.TryGetValue(s, out sources))
                    {
                        return;
                    }

                    // Create a table of each data point in the specified range
                    for (int i = 0; i < sources.Count; i++)
                    {
                        if (sources[i].Start >= source.Start)
                        {
                            sources[i].Load(source.Session);
                            for (int j = 0; j < sources[i].Count; j++)
                            {
                                if (sources[i].Time(j) <= source.End)
                                {
                                    // Add the point to the table
                                    Data.Rows.Add(source.XAxisGetValue(sources[i], j), GetValue(sources[i], j));
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                }

                // Update the line plot data
                if (Plot != null)
                {
                    Plot.SetData(Data);
                }
            }
Esempio n. 2
0
            /// <summary>
            /// Sets a new expression for the plot line
            /// </summary>
            /// <param name="source">The data source</param>
            /// <param name="expression">The new expression to set</param>
            public void SetExpression(DataChart <T> source, string expression)
            {
                System.Drawing.Color c;
                if (Plot != null)
                {
                    c = this.Color;
                    Plot.Remove(source);
                    Plot = null;
                }
                else
                {
                    c = source.PlotLineColors.Dequeue();
                    source.PlotLineColors.Enqueue(c);   // Add the color to the end of the list so that it can be re-used if needed
                }

                this.Expression = expression;
                this.GetValue   = getExpressionEvaluator(expression);
                Generate(source);

                PlotLineCreator creator;

                if (!LineCreators.TryGetValue(source.getExpressionType(Expression, GetValue), out creator))
                {
                    creator = DefaultCreator;
                }
                bool   preserveAxisPosition = (source.Plot.XAxis1 != null);
                double worldMin             = preserveAxisPosition ? source.Plot.XAxis1.WorldMin : 0;
                double worldMax             = preserveAxisPosition ? source.Plot.XAxis1.WorldMax : 0;

                Plot       = creator(source, this);
                this.Color = c;
                if (preserveAxisPosition)
                {
                    source.Plot.XAxis1.WorldMin = worldMin;
                    source.Plot.XAxis1.WorldMax = worldMax;
                }
            }