Пример #1
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 source, string expression)
 {
     this.Expression = expression;
     if (!string.IsNullOrEmpty(expression))
     {
         // Attempt to generate the data table for the given expression
         this.GetValue = source.getExpressionEvaluator(expression);
         Generate(source);
     }
     if (ExpressionChanged != null)
     {
         ExpressionChanged(this);
     }
 }
Пример #2
0
            /// <summary>
            /// Generates the data to use in the plot line
            /// </summary>
            /// <param name="source"></param>
            public void Generate(DataChart source)
            {
                if (!DataMutex.WaitOne(250))
                {
                    return;
                }
                List <string> symbols = source.GetSymbolList(Symbol);

                this.Data = new DataTable();

                foreach (var s in symbols)
                {
                    List <StockDataInterface> sources;
                    if (this.GetValue == null)
                    {
                        this.GetValue = source.getExpressionEvaluator(Expression);                           // Create the expression only when needed to speed up the GUI and allow parallel compiling
                    }
                    if (!source.getDataList(s, out sources) || (GetValue == null))
                    {
                        break;
                    }

                    // Load the sources first (need to load to the end before accessing the data since loading later sources could backfill data) */
                    for (int i = 0; i < sources.Count; i++)
                    {
                        sources[i].Load(source.Session);
                    }

                    // Ensure columns are added for the data types
                    if (Data.Columns.Count < 2)
                    {
                        Data.Columns.Add(source.XAxis, source.XAxisGetValue(sources[0], 0).GetType());
                        Data.Columns.Add(Expression, GetValue(sources[0], 0).GetType());
                    }

                    // Create a table of each data point in the specified range
                    for (int i = 0; i < sources.Count; i++)
                    {
                        string   symbol;
                        DateTime start;
                        TimeSpan interval;
                        sources[i].GetInfo(out symbol, out start, out interval);
                        if (start >= source.Start)
                        {
                            // Add the data set to the table
                            for (int j = 0; j < sources[i].GetCount(); j++)
                            {
                                if (start.AddSeconds(interval.TotalSeconds * 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
                CreatePlotLine(source);
                if (Plot != null)
                {
                    Plot.SetData(Data);
                }
                DataMutex.ReleaseMutex();
            }