当前位置: 首页>>代码示例>>C#>>正文


C# TimeSeries.Clone方法代码示例

本文整理汇总了C#中TimeSeries.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSeries.Clone方法的具体用法?C# TimeSeries.Clone怎么用?C# TimeSeries.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TimeSeries的用法示例。


在下文中一共展示了TimeSeries.Clone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawGraph

        private void DrawGraph(TimeSeries timeSeriesData, TimeSeries ts)
        {
            double width = ActualWidth;
            double height = ActualHeight;

            TimeSeries tsn = ts.Clone();
            tsn.Normalize();

            DrawLine(0, 0, width, 0, 1f);
            DrawLine(width, 0, width, height, 1f);
            DrawLine(width, height, 0, height, 1f);
            DrawLine(0, height, 0, 0, 1f);

            int numLines = 3;
            float gap = (float) height/numLines;
            for (int i = 1; i < numLines; ++i)
            {
                DrawLine(0, (int) (i*gap), width, (int) (i*gap), 0.5f);
            }

            IList<double> values = tsn.Values;

            float w = ((float) width - 40)/values.Count;
            float h = (float) height - 40;

            for (int i = 1; i < values.Count; ++i)
            {
                var line = new Line
                {
                    X1 = 20 + (i - 1)*w,
                    Y1 = 20 + (1 - values[i - 1])*h,
                    X2 = 20 + i*w,
                    Y2 = 20 + (1 - values[i])*h,
                    StrokeThickness = 4,
                    StrokeEndLineCap = PenLineCap.Round,
                    Stroke = new SolidColorBrush(Colors.White)
                };

                LineGraphCanvas.Children.Add(line);
            }

            MathLine trend = tsn.GetTrend();
            var trendline = new Line
            {
                X1 = 20 + 0,
                Y1 = 20 + (1 - trend.GetY(0))*h,
                X2 = 20 + (values.Count - 1)*w,
                Y2 = 20 + (1 - trend.GetY(values.Count - 1))*h,
                StrokeThickness = 2.5,
                Stroke = new SolidColorBrush(GetTrendColor(trend.B))
            };

            LineGraphCanvas.Children.Add(trendline);

            Title.Text = timeSeriesData.Meta.Name;

            double priceOpen = ts.Values.First();
            double priceClose = ts.Values.Last();
            Value.Text = "  " + ts.Values.Last();
            var delta = (float) Math.Round(priceClose - priceOpen, 3);
            bool isNegative = delta < 0;
            Growth.Text = "   " + (!isNegative ? "+" : "") + delta;
            GrowthRate.Text = "   " + (!isNegative ? "+" : "") + Math.Round(delta/priceOpen, 3)*100 + "%";
            Growth.Foreground = new SolidColorBrush(GetTrendColor(delta));
            GrowthRate.Foreground = new SolidColorBrush(GetTrendColor(delta));

            var labelOpen = new TextBlock();
            labelOpen.FontSize = 16;
            labelOpen.Text = ts.Meta.Min.ToString();
            LineGraphCanvas.Children.Add(labelOpen);
            labelOpen.Measure(new Size(int.MaxValue, int.MaxValue));
            Canvas.SetTop(labelOpen, height - 16);
            Canvas.SetLeft(labelOpen, -labelOpen.ActualWidth - 7);

            var labelClose = new TextBlock();
            labelClose.FontSize = 16;
            labelClose.Text = ts.Meta.Max.ToString();
            LineGraphCanvas.Children.Add(labelClose);
            labelClose.Measure(new Size(int.MaxValue, int.MaxValue));
            Canvas.SetTop(labelClose, 2);
            Canvas.SetLeft(labelClose, -labelClose.ActualWidth - 7);

            var labelStartDate = new TextBlock();
            labelStartDate.FontSize = 16;
            labelStartDate.Text = "1";
            LineGraphCanvas.Children.Add(labelStartDate);
            Canvas.SetTop(labelStartDate, height + 7);
            Canvas.SetLeft(labelStartDate, 0);

            var labelEndDate = new TextBlock();
            labelEndDate.FontSize = 16;
            labelEndDate.Text = timeSeriesData.Values.Count.ToString();
            labelEndDate.Measure(new Size(int.MaxValue, int.MaxValue));
            LineGraphCanvas.Children.Add(labelEndDate);
            Canvas.SetTop(labelEndDate, height + 7);
            Canvas.SetLeft(labelEndDate, width - labelEndDate.ActualWidth);
        }
开发者ID:philllies,项目名称:finalproject,代码行数:97,代码来源:LineGraph.xaml.cs


注:本文中的TimeSeries.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。