void CreateSampleChart()
        {
            chart.BeginUpdate();

            // random time data
            var npts = 5000;
            var xs = new DateTime[npts];
            var ys = new double[npts];

            var x0 = DateTime.Now.AddDays(-npts);
            var rnd = new Random();
            for (int i = 0; i < npts; i++)
            {
                xs[i] = x0.AddDays(i);
                ys[i] = rnd.NextDouble() * 100;
            }

            ds = new XYDataSeries() { XValuesSource = xs, ValuesSource = ys, RenderMode = RenderMode.Fast };

            chart.Data.Children.Add(ds);
            chart.ChartType = ChartType.Line;
            chart.View.AxisX.IsTime = true;
            chart.Palette = ColorGeneration.Urban;
            chart.EndUpdate();
        }
Esempio n. 2
0
        public Dynamic()
        {
            InitializeComponent();

              chart.Data.ItemsSource = _pts;
              chart.ChartType = ChartType.Line;

              XYDataSeries ds = new XYDataSeries()
              {
            XValueBinding = new Binding("X"),
            ValueBinding = new Binding("Y"),
            ConnectionStrokeThickness = 2,
            Label = "raw",
            //        ConnectionStroke = new SolidColorBrush(Colors.DarkGray)
              };

              chart.Data.Children.Add(ds);

              _tlmin = new TrendLine()
              {
            FitType = FitType.MinY,
            XValueBinding = new Binding("X"),
            ValueBinding = new Binding("Y"),
            Label = "min",
            //        ConnectionStroke = new SolidColorBrush(Colors.Blue)
              };

              _tlmax = new TrendLine()
              {
            FitType = FitType.MaxY,
            XValueBinding = new Binding("X"),
            ValueBinding = new Binding("Y"),
            Label = "max",
            //        ConnectionStroke = new SolidColorBrush(Colors.Red)
              };

              _tlavg = new TrendLine()
              {
            FitType = FitType.AverageY,
            XValueBinding = new Binding("X"),
            ValueBinding = new Binding("Y"),
            Label = "avg",
            //        ConnectionStroke = new SolidColorBrush(Colors.Green)
              };

              chart.View.AxisY.Min = -1000;
              chart.View.AxisY.Max = 1000;

              dt = new DispatcherTimer()
            { Interval = TimeSpan.FromSeconds(0.2) };
              dt.Tick += (s, e) => Update();
              dt.Start();
        }
Esempio n. 3
0
        public MainWindow()
        {
            InitializeComponent();

            #region DataCreation
            XYDataSeries Ds = new XYDataSeries();
            Ds.ChartType = ChartType.Line;

            List<int> xvalues = new List<int>();
            xvalues.Add(1);
            xvalues.Add(2);
            xvalues.Add(3);
            xvalues.Add(4);
            xvalues.Add(5);
            xvalues.Add(6);
            xvalues.Add(7);
            xvalues.Add(8);
            xvalues.Add(9);

            List<int> yvalues = new List<int>();
            yvalues.Add(200);
            yvalues.Add(130);
            yvalues.Add(303);
            yvalues.Add(442);
            yvalues.Add(190);
            yvalues.Add(239);
            yvalues.Add(400);
            yvalues.Add(350);
            yvalues.Add(9);

            Ds.XValuesSource = xvalues;
            Ds.ValuesSource = yvalues;
            #endregion

            chart.Data.Children.Add(Ds);

            var pnl = new ChartPanel();
            pnl.MouseMove += new MouseEventHandler(pnl_MouseMove);

            var vmarker = CreateMarker(false, new Point());
            pnl.Children.Add(vmarker);
            vmarker.Action = ChartPanelAction.None;

            var hmarker = CreateMarker(true, new Point());
            pnl.Children.Add(hmarker);
            hmarker.Action = ChartPanelAction.None;

               chart.View.Layers.Add(pnl);
        }
Esempio n. 4
0
        void ConfigureSamplesChart()
        {
            sampleSurface.XAxes = new List <AxisBase> {
                new NumericAxis
                {
                    AutoRange          = AutoRange.Always,
                    DrawMajorBands     = false,
                    DrawLabels         = false,
                    DrawMajorTicks     = false,
                    DrawMinorTicks     = false,
                    DrawMajorGridLines = false,
                    DrawMinorGridLines = false
                }
            };


            sampleSurface.YAxes = new List <AxisBase> {
                new NumericAxis
                {
                    AutoRange    = AutoRange.Never,
                    VisibleRange = new DoubleRange {
                        Min = short.MinValue, Max = short.MaxValue
                    },
                    DrawMajorBands     = false,
                    DrawLabels         = false,
                    DrawMajorTicks     = false,
                    DrawMinorTicks     = false,
                    DrawMajorGridLines = false,
                    DrawMinorGridLines = false
                }
            };

            samplesDataSeries = new XYDataSeries <int, int> {
                FifoCapacity = 500000
            };

            var lineSeries = new LineRenderableSeries();

            lineSeries.DataSeries = samplesDataSeries;

            sampleSurface.ChartSeries = lineSeries;
        }
        /// <summary>
        /// 标签左键隐藏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Label_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            LegendItem cli = (sender as Label).DataContext as LegendItem;

            if (cli != null)
            {
                XYDataSeries ds = cli.Item as XYDataSeries;
                if (ds != null)
                {
                    if (ds.Visibility != Visibility.Hidden)
                    {
                        ds.Visibility = Visibility.Hidden;
                        ds.SymbolFill = new SolidColorBrush(Colors.Gray);
                    }
                    else
                    {
                        ds.Visibility = Visibility.Visible;
                        ds.SymbolFill = ds.ConnectionFill;
                    }
                }
            }
        }
        public ConcentrationComOne()
        {
            InitializeComponent();
            ConcChart.ChartType = ChartType.Line;

            ds1 = new XYDataSeries()
            {
                ConnectionStrokeThickness = 1,
                Label = "气体1",
            };
            ds2 = new XYDataSeries()
            {
                ConnectionStrokeThickness = 1,
                Label = "气体2",
            };
            ds3 = new XYDataSeries()
            {
                ConnectionStrokeThickness = 1,
                Label = "气体3",
            };
            ds4 = new XYDataSeries()
            {
                ConnectionStrokeThickness = 1,
                Label = "气体4",
            };
            ConcChart.Data.Children.Add(ds1);
            ConcChart.Data.Children.Add(ds2);
            ConcChart.Data.Children.Add(ds3);
            ConcChart.Data.Children.Add(ds4);
            ConcChart.View.AxisY.AutoMin = true;
            ConcChart.View.AxisY.AutoMax = true;
            dt = new DispatcherTimer()
            {
                Interval = TimeSpan.FromSeconds(0.4)
            };
            dt.Tick += (s, e) => Update();
            dt.Start();
        }
Esempio n. 7
0
        public virtual void Create(C1Chart chart, IDataSeries[] dss, int npts)
        {
            Reset(chart);

            IEnumerable x = null;

            for (int i = 0; i < dss.Length; i++)
            {
                DataSeries ds = null;
                if (i < chart.Data.Children.Count)
                {
                    ds = (DataSeries)chart.Data.Children[i];
                    dss[i].Update(ds, npts);
                }
                else
                {
                    ds = dss[i].Create(npts);
                }

                XYDataSeries xds = ds as XYDataSeries;
                if (xds != null)
                {
                    if (x == null)
                    {
                        x = xds.XValuesSource;
                    }
                    else
                    {
                        xds.XValuesSource = x;
                    }
                }

                if (!chart.Data.Children.Contains(ds))
                {
                    chart.Data.Children.Add(ds);
                }
            }
        }
Esempio n. 8
0
        void ConfigureFFTChart()
        {
            fftSurface.XAxes = new List <AxisBase> {
                new NumericAxis
                {
                    AutoRange    = AutoRange.Never,
                    VisibleRange = new DoubleRange {
                        Min = 0, Max = 1024
                    },
                    DrawMajorBands     = false,
                    DrawLabels         = false,
                    DrawMajorTicks     = false,
                    DrawMinorTicks     = false,
                    DrawMajorGridLines = false,
                    DrawMinorGridLines = false
                }
            };

            fftSurface.YAxes = new List <AxisBase> {
                new NumericAxis
                {
                    AutoRange    = AutoRange.Never,
                    VisibleRange = new DoubleRange {
                        Min = -30, Max = 60
                    },
                    DrawMinorGridLines = false,
                    DrawMinorTicks     = false,
                    AxisAlignment      = AxisAlignment.Left
                }
            };
            fftDataSeries = new XYDataSeries <int, int>();

            var columnSeries = new ColumnRenderableSeries();

            columnSeries.DataSeries = fftDataSeries;

            fftSurface.ChartSeries = columnSeries;
        }
Esempio n. 9
0
        void CreateParametric()
        {
            double[] x = new double[cnt];
            double[] y = new double[cnt];

            double kx = rnd.Next(1, 5);
            double ky = rnd.Next(1, 5);
            for (int i = 0; i < cnt; i++)
            {
                x[i] = (cnt - i - 1) * Math.Sin(0.1 * kx * i);
                y[i] = (cnt - i - 1) * Math.Cos(0.1 * ky * i);
            }

            c1Chart1.BeginUpdate();
            c1Chart1.Data.Children.Clear();
            XYDataSeries ds = new XYDataSeries();
            ds.ValuesSource = x;
            ds.XValuesSource = y;
            ds.SymbolStyle = (Style)FindResource("sstyle");
            ds.ConnectionStyle = (Style)FindResource("cstyle");
            c1Chart1.Data.Children.Add(ds);
            c1Chart1.EndUpdate();
        }
Esempio n. 10
0
        public DataSeries CreateDataSeries(int npts, bool invert = false)
        {
            var ds = new XYDataSeries() { SymbolSize = new Size(20, 20) };

            int cnt = npts;
            var x = new double[cnt];
            var y = new double[cnt];

            for (int i = 0; i < cnt; i++)
            {
                x[i] = i; y[i] = rnd.NextDouble();
            }

            if (invert)
            {
                ds.XValuesSource = y; ds.ValuesSource = x;
            }
            else
            {
                ds.XValuesSource = x; ds.ValuesSource = y;
            }
            return ds;
        }
        public static DataSeries CreateDataSeries(int npts, bool invert)
        {
            var ds = new XYDataSeries();// { SymbolSize = new Size(5, 5), ConnectionStrokeThickness = 1 };

            int cnt = npts;
            var x   = new double[cnt];
            var y   = new double[cnt];

            for (int i = 0; i < cnt; i++)
            {
                x[i] = i; y[i] = rnd.NextDouble();
            }

            if (invert)
            {
                ds.XValuesSource = y; ds.ValuesSource = x;
            }
            else
            {
                ds.XValuesSource = x; ds.ValuesSource = y;
            }
            return(ds);
        }
Esempio n. 12
0
        static void XYPlotProcess(Chart chart, PropertyInfo[] props)
        {
            int          length = props.Length;
            XYDataSeries series = null;

            for (int i = 0; i < length; i++)
            {
                PropertyInfo info = props[i];
                if (IsSupported(info.PropertyType))
                {
                    if (series == null)
                    {
                        series = new XYDataSeries {
                            AutoGenerated = true
                        };
                        series.Label = info.Name;
                        Binding binding = new Binding();
                        binding.Path         = new PropertyPath(info.Name);
                        series.XValueBinding = binding;
                    }
                    else
                    {
                        Binding binding2 = new Binding();
                        binding2.Path       = new PropertyPath(info.Name);
                        series.ValueBinding = binding2;
                        chart.Data.Children.Add(series);
                        series = null;
                    }
                }
            }
            if ((series != null) && (series.ValueBinding == null))
            {
                series.ValueBinding  = series.XValueBinding;
                series.XValueBinding = null;
                chart.Data.Children.Add(series);
            }
        }
Esempio n. 13
0
 void UpdateDataSeries(XYDataSeries <int, int> dataSeries)
 {
     samplesQueue.Enqueue(dataSeries.YValues);
     ++arraysToPickUp;
 }
        // ** utilities
        void CreateDataSeries(C1Chart chart, WeatherData[] data)
        {
            chart.Data.Children.Clear();

            #if DataBinding
              chart.Data.ItemsSource = data;
            #else
              int len = data.Length;
              DateTime[] days = new DateTime[len];
              double[] tmin = new double[len];
              double[] tmax = new double[len];
              double[] tavg = new double[len];
              for (int i = 0; i < len; i++)
              {
            days[i] = data[i].DateTime;
            tmin[i] = data[i].TMin;
            tmax[i] = data[i].TMax;
            tavg[i] = data[i].TAvg;
              }
            #endif

              XYDataSeries ds = new XYDataSeries(); ds.Label = "Minimum";
            #if DataBinding
              ds.ValueBinding = new Binding("TMin");
              ds.XValueBinding = new Binding("DateTime");
            #else
              ds.XValuesSource = days;
              ds.ValuesSource = tmin;
            #endif
              ds.ConnectionStroke = new SolidColorBrush(Colors.Blue);
              chart.Data.Children.Add(ds);

              ds = new XYDataSeries(); ds.Label = "Maximum";
            #if DataBinding
              ds.ValueBinding = new Binding("TMax");
              ds.XValueBinding = new Binding("DateTime");
            #else
              ds.XValuesSource = days;
              ds.ValuesSource = tmax;
            #endif
              ds.ConnectionStroke = new SolidColorBrush(Colors.Red);
              chart.Data.Children.Add(ds);

              ds = new XYDataSeries(); ds.Label = "Average";
            #if DataBinding
              ds.ValueBinding = new Binding("TAvg");
              ds.XValueBinding = new Binding("DateTime");
            #else
              ds.XValuesSource = days;
              ds.ValuesSource = tavg;
            #endif
              chart.Data.Children.Add(ds);

              foreach (DataSeries ser in chart.Data.Children)
            ser.ConnectionStrokeThickness = 1;

              chart.View.AxisX.IsTime = true;
              chart.View.AxisX.AnnoPosition = AnnoPosition.Near;
        }
Esempio n. 15
0
        private void SetTemperatureChart()
        {
            // read data
            CSVData data = new CSVData();
            using (Stream stream = Assembly.GetExecutingAssembly().
                GetManifestResourceStream("ChartSamples.Resources.weatherYear.csv"))
            {
                data.Read(stream, true, true);
            }

            int len = data.Length;
            WeatherData[] wdata = new WeatherData[len];

            double min = double.MaxValue;
            double max = double.MinValue;

            // fill the array
            for (int i = 0; i < len; i++)
            {
                wdata[i] = new WeatherData(DateTime.Parse(data[i, 0]),
                      double.Parse(data[i, "Max TemperatureF"]),
                      double.Parse(data[i, "Mean TemperatureF"]),
                      double.Parse(data[i, "Min TemperatureF"]));

                min = Math.Min(min, wdata[i].TMin);
                max = Math.Max(max, wdata[i].TMax);
            }

            if (len > 0)
            {
                chart.BeginUpdate();
                chart.Data.Children.Clear();
                chart.Data.ItemsSource = wdata;

                // create data series
                HighLowSeries ds = new HighLowSeries();
                ds.ChartType = ChartType.Gantt;
                ds.Label = "Temp";
                ds.LowValueBinding = new Binding("TMin");
                ds.XValueBinding = new Binding("DateTime");
                ds.HighValueBinding = new Binding("TMax");
                ds.Style = this.Resources["highlowseries"] as Style;

                chart.Data.Children.Add(ds);

                XYDataSeries ds2 = new XYDataSeries();
                ds2.ChartType = ChartType.Line;
                ds2.Label = "Average";
                ds2.ValueBinding = new Binding("TAvg");
                ds2.XValueBinding = new Binding("DateTime");
                chart.Data.Children.Add(ds2);

                // set axis min and max
                chart.View.AxisX.Min = wdata[0].DateTime.Subtract(new TimeSpan(1, 0, 0, 0)).ToOADate();
                chart.View.AxisX.Max = wdata[len - 1].DateTime.ToOADate();

                chart.View.AxisY.Min = min;
                chart.View.AxisY.Max = max;

                // style chart
                chart.View.AxisX.IsTime = true;
                chart.View.AxisY.MajorTickThickness = 0;
                chart.View.AxisY.MinorTickThickness = 0;
                chart.View.AxisY.AxisLine = new Line() { StrokeThickness = 0 };
                chart.View.AxisX.Scale = 0.4;
                chart.View.AxisX.ScrollBar = new AxisScrollBar();
                chart.View.AxisX.MajorGridStrokeThickness = 0;
                chart.View.AxisX.MinorGridStrokeThickness = 0;
                chart.View.AxisX.MajorTickThickness = 0;
                chart.View.AxisX.MinorTickThickness = 0;
                chart.View.AxisX.AxisLine = new Line() { StrokeThickness = 0 };
                chart.View.AxisY.Title = new TextBlock() { Text = "Temperature", HorizontalAlignment = System.Windows.HorizontalAlignment.Center };

                chart.EndUpdate();
            }
        }
        void chart_Loaded(object sender, RoutedEventArgs e)
        {
            // read data from resource
            CSVData data = new CSVData();

            using (Stream stream = Assembly.GetExecutingAssembly().
                                   GetManifestResourceStream("ChartSamples.Resources.weather.csv"))
            {
                data.Read(stream, true, false);
            }

            int len = data.Length;

            DateTime[] dts  = new DateTime[len];
            double[]   t    = new double[len];
            Brush      red  = new SolidColorBrush(Colors.Red);
            Brush      blue = new SolidColorBrush(Colors.Blue);

            DateTime day = new DateTime(), dtmin = new DateTime(), dtmax = new DateTime();
            double   tmax = double.MinValue, tmin = double.MaxValue;

            // collection for min/max values axis source
            List <KeyValuePair <object, double> > kvals = new List <KeyValuePair <object, double> >();

            // fill up the time and temperature arrays
            // and calculate daily min/max
            for (int i = 0; i < len; i++)
            {
                dts[i] = DateTime.Parse(data[i, "date"] + " " + data[i, "time"], CultureInfo.InvariantCulture);
                t[i]   = double.Parse(data[i, "T"], CultureInfo.InvariantCulture);

                if (i == 0)
                {
                    day = dts[i].Date; dtmax = dtmin = dts[i]; tmax = tmin = t[i];
                }

                if (dts[i].Date == day)
                {
                    if (t[i] > tmax)
                    {
                        tmax  = t[i];
                        dtmax = dts[i];
                    }
                    if (t[i] < tmin)
                    {
                        tmin  = t[i];
                        dtmin = dts[i];
                    }
                }
                else
                {
                    kvals.Add(new KeyValuePair <object, double>(
                                  new TextBlock()
                    {
                        Text = "low", Foreground = blue
                    }, dtmin.ToOADate()));
                    kvals.Add(new KeyValuePair <object, double>(
                                  new TextBlock()
                    {
                        Text = "high", Foreground = red
                    }, dtmax.ToOADate()));
                    day = dts[i].Date; dtmax = dtmin = dts[i]; tmax = tmin = t[i];
                }
            }

            chart.BeginUpdate();

            // create data series
            XYDataSeries ds = new XYDataSeries()
            {
                XValuesSource             = dts,
                ValuesSource              = t,
                ConnectionStrokeThickness = 2,
//        ConnectionStroke = new SolidColorBrush(Colors.Green)
            };

            chart.Data.Children.Add(ds);
            chart.ChartType = ChartType.Line;

            double xsc = 0.05;

            // main x-axis for time
            Axis axx = chart.View.AxisX;

            axx.Min             = dts[0].ToOADate();
            axx.Max             = dts[len - 1].ToOADate();
            axx.Value           = 0;
            axx.Scale           = xsc;
            axx.IsTime          = true;
            axx.MajorUnit       = 0.25;
            axx.AnnoFormat      = "HH";
            axx.MajorGridStroke = null;
            axx.AnnoTemplate    = new TextBlock()
            {
                FontSize = 8, Foreground = Foreground
            };
            axx.Foreground = Foreground;
            axx.ScrollBar  = new AxisScrollBar();

            // auxiliary x-axis for dates
            Axis ax = new Axis()
            {
                AxisType                 = AxisType.X,
                AnnoFormat               = "d MMM",
                AnnoPosition             = AnnoPosition.Near,
                IsDependent              = true,
                MajorUnit                = 1,
                IsTime                   = true,
                MajorGridStroke          = Foreground,
                MajorGridStrokeThickness = 1.5
            };

            chart.View.Axes.Add(ax);

            // create auxiliary x-axis for daily min/max
            ax = new Axis()
            {
                AxisType    = AxisType.X,
                Position    = AxisPosition.Far,
                IsDependent = true,
                //AnnoAngle = -90,
                ItemsSource              = kvals,
                MajorGridStroke          = new SolidColorBrush(Colors.LightGray),
                MajorGridStrokeThickness = 1,
                MajorGridStrokeDashes    = new DoubleCollection()
                {
                    1, 2
                },
            };
            chart.View.Axes.Add(ax);

            chart.EndUpdate();

            chart.Loaded -= new RoutedEventHandler(chart_Loaded);
        }
        // ** utilities
        void CreateDataSeries(C1Chart chart, WeatherData[] data)
        {
            chart.Data.Children.Clear();

#if DataBinding
            chart.Data.ItemsSource = data;
#else
            int        len  = data.Length;
            DateTime[] days = new DateTime[len];
            double[]   tmin = new double[len];
            double[]   tmax = new double[len];
            double[]   tavg = new double[len];
            for (int i = 0; i < len; i++)
            {
                days[i] = data[i].DateTime;
                tmin[i] = data[i].TMin;
                tmax[i] = data[i].TMax;
                tavg[i] = data[i].TAvg;
            }
#endif

            XYDataSeries ds = new XYDataSeries(); ds.Label = "Minimum";
#if DataBinding
            ds.ValueBinding  = new Binding("TMin");
            ds.XValueBinding = new Binding("DateTime");
#else
            ds.XValuesSource = days;
            ds.ValuesSource  = tmin;
#endif
            ds.ConnectionStroke = new SolidColorBrush(Colors.Blue);
            chart.Data.Children.Add(ds);

            ds = new XYDataSeries(); ds.Label = "Maximum";
#if DataBinding
            ds.ValueBinding  = new Binding("TMax");
            ds.XValueBinding = new Binding("DateTime");
#else
            ds.XValuesSource = days;
            ds.ValuesSource  = tmax;
#endif
            ds.ConnectionStroke = new SolidColorBrush(Colors.Red);
            chart.Data.Children.Add(ds);

            ds = new XYDataSeries(); ds.Label = "Average";
#if DataBinding
            ds.ValueBinding  = new Binding("TAvg");
            ds.XValueBinding = new Binding("DateTime");
#else
            ds.XValuesSource = days;
            ds.ValuesSource  = tavg;
#endif
            chart.Data.Children.Add(ds);

            foreach (DataSeries ser in chart.Data.Children)
            {
                ser.ConnectionStrokeThickness = 1;
            }

            chart.View.AxisX.IsTime       = true;
            chart.View.AxisX.AnnoPosition = AnnoPosition.Near;
        }
Esempio n. 18
0
        private void DrawGhpics(DamWebAPI.ViewModel.Entity.Graphics graInfo)
        {
            c1Chart.BeginUpdate();

            double dashPixels = ResetChart();

            //一次性查询所有的数据

            var results = from i in graInfo.Lines
                          where i.IsShow == true
                          group i by i.UnitSymbol;  //根据 物理量单位 判断是不是同一类量

            List <CalculateValue> allCalcValues = null;

            tby1.Text = tby2.Text = tbcaption.Text = "";

            int lineIndex = 0;

            //根据多少个Y轴进行循环
            for (int i = 0; i < results.Count(); i++)
            {
                if (allCalcValues == null)
                {
                    //避免多个枚举
                    allCalcValues = ViewModel.GetAllCalcValues(graInfo).ToList();
                }

                //有N个Y轴
                Axis      yAxis   = null;
                TextBlock tbTitle = null;
                if (i == 0)
                {
                    yAxis      = c1Chart.View.AxisY;
                    yAxis.Name = "y1";

                    //set axis title
                    tbTitle = tby1;

                    yAxis.MajorGridStrokeDashes = new DoubleCollection(new double[] { dashPixels, dashPixels });
                }
                else
                {
                    //创建新的axis
                    yAxis = new Axis
                    {
                        AxisType = AxisType.Y,
                        Position = AxisPosition.Far,
                        Name     = "y" + (i + 1).ToString(),
                    };

                    c1Chart.View.Axes.Add(yAxis);
                    tbTitle = tby2;

                    //hid grid lines
                    yAxis.MajorGridStroke = Brushes.White;
                    yAxis.MinorGridStroke = Brushes.White;
                }

                string unitSymbol = results.ElementAt(i).Key;

                var groupItems = results.ElementAt(i).ToList();

                //物理量名称
                string calcName = groupItems.First().ParamName;

                if (groupItems.Count > 1)
                {
                    //有多个相同单位的物理量
                    calcName = "单位";
                }

                tbTitle.Text = string.Format("{0} {1}: {2}", tbTitle.Text, calcName, unitSymbol);



                for (int gi = 0; gi < groupItems.Count; gi++)
                {
                    var          item = groupItems.ElementAt(gi);
                    XYDataSeries ds   = new XYDataSeries();
                    if (gi == 0)
                    {
                        ds.PlotElementLoaded += ds_PlotElementLoaded;
                    }

                    ds.Label = item.LegendName;
                    var valCollection = (from val in allCalcValues
                                         where val.ParamId == item.ParamId
                                         orderby val.Date
                                         select val);

                    ObservableCollection <CalculateValue> collection = new ObservableCollection <CalculateValue>(valCollection);
                    //消除异常值

                    HandleErrorValue(collection);

                    ds.ItemsSource = collection;

                    ds.XValueBinding = new Binding("Date.DateTime");
                    ds.ValueBinding  = new Binding("Val");

                    //ds.XValuesSource = (from val in valCollection
                    //                    select val.Date.DateTime).ToArray();
                    //ds.ValuesSource = (from val in valCollection
                    //                   select val.Val).ToArray();

                    ds.AxisY = yAxis.Name;
                    //set line style
                    lineIndex = setLineStyle(lineIndex, ds);
                    c1Chart.Data.Children.Add(ds);
                }
            }
            c1Chart.EndUpdate();
        }
Esempio n. 19
0
 public static void AutoCreateSeries(Chart chart, IEnumerable items)
 {
     if (chart.AutoGenerateSeries)
     {
         chart.Data.notify = false;
         List <DataSeries> list = new List <DataSeries>();
         foreach (DataSeries series in chart.Data.Children)
         {
             if (series.AutoGenerated)
             {
                 list.Add(series);
             }
         }
         if (list.Count > 0)
         {
             foreach (DataSeries series2 in list)
             {
                 chart.Data.Children.Remove(series2);
             }
         }
         bool           autoGenerateSeries = chart.AutoGenerateSeries;
         ChartBindings  bindings           = chart.Bindings;
         List <Binding> seriesBindings     = null;
         Binding        xBinding           = null;
         if (bindings != null)
         {
             seriesBindings = bindings.SeriesBindings;
             xBinding       = bindings.XBinding;
         }
         Type itemType = GetItemType(items);
         if (IsSupported(itemType))
         {
             DataSeries series3 = null;
             if (itemType == typeof(Point))
             {
                 XYDataSeries series4 = new XYDataSeries {
                     AutoGenerated = true
                 };
                 Binding binding2 = new Binding();
                 binding2.Path         = new PropertyPath("X");
                 series4.XValueBinding = binding2;
                 Binding binding3 = new Binding();
                 binding3.Path             = new PropertyPath("Y");
                 series4.ValueBinding      = binding3;
                 series4.FireNotifications = false;
                 series3 = series4;
             }
             else
             {
                 series3 = new DataSeries {
                     AutoGenerated     = true,
                     FireNotifications = false
                 };
                 series3.ValuesSource = items;
             }
             chart.Data.Children.Add(series3);
         }
         else if ((seriesBindings != null) && (seriesBindings.Count > 0))
         {
             foreach (Binding binding4 in seriesBindings)
             {
                 DataSeries series6 = null;
                 if (xBinding != null)
                 {
                     series6 = new XYDataSeries();
                 }
                 else
                 {
                     series6 = new DataSeries();
                 }
                 series6.AutoGenerated = true;
                 if ((binding4.Path != null) && !string.IsNullOrEmpty(binding4.Path.Path))
                 {
                     series6.Label = binding4.Path.Path;
                 }
                 series6.ValueBinding = binding4;
                 chart.Data.Children.Add(series6);
             }
         }
         else if (itemType != null)
         {
             PropertyInfo[] props = Enumerable.ToArray <PropertyInfo>(IntrospectionExtensions.GetTypeInfo(itemType).DeclaredProperties);
             if (props != null)
             {
                 if (xBinding != null)
                 {
                     int length = props.Length;
                     for (int i = 0; i < length; i++)
                     {
                         PropertyInfo info = props[i];
                         if ((info.Name != xBinding.Path.ToString()) && IsSupported(info.PropertyType))
                         {
                             XYDataSeries series7 = new XYDataSeries {
                                 AutoGenerated = true
                             };
                             series7.Label = info.Name;
                             Binding binding5 = new Binding();
                             binding5.Path        = new PropertyPath(info.Name);
                             series7.ValueBinding = binding5;
                             chart.Data.Children.Add(series7);
                         }
                     }
                 }
                 else if (chart.ChartType == ChartType.XYPlot)
                 {
                     XYPlotProcess(chart, props);
                 }
                 else
                 {
                     DefaultProcess(chart, props);
                 }
             }
         }
         chart.Data.notify = true;
     }
 }
Esempio n. 20
0
        public static DataSeries CreateDataSeries2(int npts, bool invert)
        {
            var ds = new XYDataSeries() { SymbolSize = new Size(5, 5), ConnectionStrokeThickness = 1 };

              int cnt = npts;
              var x = new double[2 * cnt];
              var y = new double[2 * cnt];

              for (int i = 0; i < cnt; i++)
              {
            x[i] = i; y[i] = rnd.NextDouble();
              }

              for (int i = 0; i < cnt; i++)
              {
            x[cnt + i] = cnt - i - 1; y[cnt + i] = rnd.NextDouble();
              }

              if (invert)
              {
            ds.XValuesSource = y; ds.ValuesSource = x;
              }
              else
              {
            ds.XValuesSource = x; ds.ValuesSource = y;
              }
              return ds;
        }
Esempio n. 21
0
        public override DataSeries Create(int n)
        {
            XYDataSeries ds = new XYDataSeries();

              Update(ds, n);

              return ds;
        }
Esempio n. 22
0
        void chart_Loaded(object sender, RoutedEventArgs e)
        {
            // read data from resource
              CSVData data = new CSVData();

              using (Stream stream = Assembly.GetExecutingAssembly().
            GetManifestResourceStream("ChartSamples.Resources.weather.csv"))
              {
            data.Read(stream, true, false);
              }

              int len = data.Length;
              DateTime[] dts = new DateTime[len];
              double[] t = new double[len];
              Brush red = new SolidColorBrush(Colors.Red);
              Brush blue = new SolidColorBrush(Colors.Blue);

              DateTime day = new DateTime(), dtmin = new DateTime(), dtmax = new DateTime();
              double tmax = double.MinValue, tmin = double.MaxValue;

              // collection for min/max values axis source
              List<KeyValuePair<object, double>> kvals = new List<KeyValuePair<object, double>>();

              // fill up the time and temperature arrays
              // and calculate daily min/max
              for (int i = 0; i < len; i++)
              {
            dts[i] = DateTime.Parse(data[i, "date"] + " " + data[i, "time"],CultureInfo.InvariantCulture);
            t[i] = double.Parse(data[i, "T"],CultureInfo.InvariantCulture);

            if (i == 0)
            {
              day = dts[i].Date; dtmax = dtmin = dts[i]; tmax = tmin = t[i];
            }

            if (dts[i].Date == day)
            {
              if (t[i] > tmax)
              {
            tmax = t[i];
            dtmax = dts[i];
              }
              if (t[i] < tmin)
              {
            tmin = t[i];
            dtmin = dts[i];
              }
            }
            else
            {
              kvals.Add(new KeyValuePair<object, double>(
              new TextBlock() { Text = "low", Foreground = blue }, dtmin.ToOADate()));
              kvals.Add(new KeyValuePair<object, double>(
              new TextBlock() { Text = "high", Foreground = red }, dtmax.ToOADate()));
              day = dts[i].Date; dtmax = dtmin = dts[i]; tmax = tmin = t[i];
            }
              }

              chart.BeginUpdate();

              // create data series
              XYDataSeries ds = new XYDataSeries()
              {
            XValuesSource = dts,
            ValuesSource = t,
            ConnectionStrokeThickness = 2,
            //        ConnectionStroke = new SolidColorBrush(Colors.Green)
              };
              chart.Data.Children.Add(ds);
              chart.ChartType = ChartType.Line;

              double xsc = 0.05;

              // main x-axis for time
              Axis axx = chart.View.AxisX;
              axx.Min = dts[0].ToOADate();
              axx.Max = dts[len - 1].ToOADate();
              axx.Value = 0;
              axx.Scale = xsc;
              axx.IsTime = true;
              axx.MajorUnit = 0.25;
              axx.AnnoFormat = "HH";
              axx.MajorGridStroke = null;
              axx.AnnoTemplate = new TextBlock() { FontSize = 8, Foreground=Foreground};
              axx.Foreground = Foreground;
              axx.ScrollBar = new AxisScrollBar();

              // auxiliary x-axis for dates
              Axis ax = new Axis()
              {
            AxisType = AxisType.X,
            AnnoFormat = "d MMM",
            AnnoPosition = AnnoPosition.Near,
            IsDependent = true,
            MajorUnit = 1,
            IsTime = true,
            MajorGridStroke = Foreground,
            MajorGridStrokeThickness = 1.5
              };
              chart.View.Axes.Add(ax);

              // create auxiliary x-axis for daily min/max
              ax = new Axis()
              {
            AxisType = AxisType.X,
            Position = AxisPosition.Far,
            IsDependent = true,
            //AnnoAngle = -90,
            ItemsSource = kvals,
            MajorGridStroke = new SolidColorBrush(Colors.LightGray),
            MajorGridStrokeThickness = 1,
            MajorGridStrokeDashes = new DoubleCollection() { 1, 2 },
              };
              chart.View.Axes.Add(ax);

              chart.EndUpdate();

              chart.Loaded -= new RoutedEventHandler(chart_Loaded);
        }
        /// <summary>
        /// 设置并返回数据线
        /// </summary>
        /// <param name="i">lineNum</param>
        /// <returns>数据线</returns>
        private DataSeries SetDataSeries(List <string> yListCollect, int i)
        {
            XYDataSeries dataSeries = new XYDataSeries
            {
                Label = "MES",
                ConnectionStrokeThickness = 1
            };

            if (i > -1)
            {
                dataSeries.Label = "IMP_" + i;
            }
            double[] valueY = new double[pixelNumber];
            double[] valueX = new double[pixelNumber];
            //像素-电压
            if (IsPixel && IsVoltage)
            {
                for (int j = 0; j < yListCollect.Count; j++)
                {
                    valueX[j] = j + 1;
                    valueY[j] = double.Parse(yListCollect[j]) * FACTOR_VOL_TO_INTEG;
                }
                ;
                dataSeries.XValuesSource = valueX;
                dataSeries.ValuesSource  = valueY;
            }
            //像素-积分
            else if (IsPixel && !IsVoltage)
            {
                for (int j = 0; j < yListCollect.Count; j++)
                {
                    valueX[j] = j + 1;
                    valueY[j] = double.Parse(yListCollect[j]);
                }
                ;
                dataSeries.XValuesSource = valueX;
                dataSeries.ValuesSource  = valueY;
            }
            //波长-电压
            else if (!IsPixel && IsVoltage)
            {
                for (int j = 0; j < yListCollect.Count; j++)
                {
                    valueX[j] = GetWaveByPixel(j + 1);
                    valueY[j] = double.Parse(yListCollect[j]) * FACTOR_VOL_TO_INTEG;
                }
                ;
                dataSeries.XValuesSource = valueX;
                dataSeries.ValuesSource  = valueY;
            }
            //波长-积分
            else if (!IsPixel && !IsVoltage)
            {
                for (int j = 0; j < yListCollect.Count; j++)
                {
                    valueX[j] = GetWaveByPixel(j + 1);
                    valueY[j] = double.Parse(yListCollect[j]);
                }
                ;
                dataSeries.XValuesSource = valueX;
                dataSeries.ValuesSource  = valueY;
            }
            return(dataSeries);
        }
        private void SetTemperatureChart()
        {
            // read data
            CSVData data = new CSVData();

            using (Stream stream = Assembly.GetExecutingAssembly().
                                   GetManifestResourceStream("ChartSamples.Resources.weatherYear.csv"))
            {
                data.Read(stream, true, true);
            }

            int len = data.Length;

            WeatherData[] wdata = new WeatherData[len];

            double min = double.MaxValue;
            double max = double.MinValue;

            // fill the array
            for (int i = 0; i < len; i++)
            {
                wdata[i] = new WeatherData(DateTime.Parse(data[i, 0]),
                                           double.Parse(data[i, "Max TemperatureF"]),
                                           double.Parse(data[i, "Mean TemperatureF"]),
                                           double.Parse(data[i, "Min TemperatureF"]));

                min = Math.Min(min, wdata[i].TMin);
                max = Math.Max(max, wdata[i].TMax);
            }

            if (len > 0)
            {
                chart.BeginUpdate();
                chart.Data.Children.Clear();
                chart.Data.ItemsSource = wdata;


                // create data series
                HighLowSeries ds = new HighLowSeries();
                ds.ChartType        = ChartType.Gantt;
                ds.Label            = "Temp";
                ds.LowValueBinding  = new Binding("TMin");
                ds.XValueBinding    = new Binding("DateTime");
                ds.HighValueBinding = new Binding("TMax");
                ds.Style            = this.Resources["highlowseries"] as Style;

                chart.Data.Children.Add(ds);

                XYDataSeries ds2 = new XYDataSeries();
                ds2.ChartType     = ChartType.Line;
                ds2.Label         = "Average";
                ds2.ValueBinding  = new Binding("TAvg");
                ds2.XValueBinding = new Binding("DateTime");
                chart.Data.Children.Add(ds2);

                // set axis min and max
                chart.View.AxisX.Min = wdata[0].DateTime.Subtract(new TimeSpan(1, 0, 0, 0)).ToOADate();
                chart.View.AxisX.Max = wdata[len - 1].DateTime.ToOADate();

                chart.View.AxisY.Min = min;
                chart.View.AxisY.Max = max;

                // style chart
                chart.View.AxisX.IsTime             = true;
                chart.View.AxisY.MajorTickThickness = 0;
                chart.View.AxisY.MinorTickThickness = 0;
                chart.View.AxisY.AxisLine           = new Line()
                {
                    StrokeThickness = 0
                };
                chart.View.AxisX.Scale     = 0.4;
                chart.View.AxisX.ScrollBar = new AxisScrollBar();
                chart.View.AxisX.MajorGridStrokeThickness = 0;
                chart.View.AxisX.MinorGridStrokeThickness = 0;
                chart.View.AxisX.MajorTickThickness       = 0;
                chart.View.AxisX.MinorTickThickness       = 0;
                chart.View.AxisX.AxisLine = new Line()
                {
                    StrokeThickness = 0
                };
                chart.View.AxisY.Title = new TextBlock()
                {
                    Text = "Temperature", HorizontalAlignment = System.Windows.HorizontalAlignment.Center
                };

                chart.EndUpdate();
            }
        }
        public MultipleAxes()
        {
            InitializeComponent();

            // read data
            CSVData data = new CSVData();

            using (Stream stream = Assembly.GetExecutingAssembly().
                                   GetManifestResourceStream("ChartSamples.Resources.weatherYear.csv"))
            {
                data.Read(stream, true, true);
            }

            int len = data.Length;

            WeatherData[] wdata = new WeatherData[len];

            double min = double.MaxValue;
            double max = double.MinValue;

            // fill the array
            for (int i = 0; i < len; i++)
            {
                wdata[i] = new WeatherData(DateTime.Parse(data[i, 0]),
                                           double.Parse(data[i, "Max TemperatureF"]),
                                           double.Parse(data[i, "Mean TemperatureF"]),
                                           double.Parse(data[i, "Min TemperatureF"]));

                min = Math.Min(min, wdata[i].TMin);
                max = Math.Max(max, wdata[i].TMax);
            }

            if (len > 0)
            {
                chart.BeginUpdate();
                chart.Data.Children.Clear();
                chart.Data.ItemsSource = wdata;

                Style ss = (Style)Resources["sstyle"];

                // create data series
                XYDataSeries ds = new XYDataSeries(); ds.Label = "Minimum";
                ds.ValueBinding  = new Binding("TMin");
                ds.XValueBinding = new Binding("DateTime");
                ds.SymbolStyle   = ss;
                chart.Data.Children.Add(ds);

                ds = new XYDataSeries(); ds.Label = "Maximum";
                ds.ValueBinding  = new Binding("TMax");
                ds.XValueBinding = new Binding("DateTime");
                ds.SymbolStyle   = ss;
                chart.Data.Children.Add(ds);

                //ds = new XYDataSeries(); ds.Label = "Average";
                //ds.ValueBinding = new Binding("TAvg");
                //ds.XValueBinding = new Binding("DateTime");
                //ds.SymbolStyle = ss;
                //chart.Data.Children.Add(ds);

                chart.View.AxisX.Min = wdata[0].DateTime.ToOADate();
                chart.View.AxisX.Max = wdata[len - 1].DateTime.ToOADate();

                chart.View.AxisY.Min = min;
                chart.View.AxisY.Max = max;

                chart.EndUpdate();
            }

            WaitAndDisableAnimation();
        }
Esempio n. 26
0
        public MultipleAxes()
        {
            InitializeComponent();

              // read data
              CSVData data = new CSVData();
              using (Stream stream = Assembly.GetExecutingAssembly().
              GetManifestResourceStream("ChartSamples.Resources.weatherYear.csv"))
              {
              data.Read(stream, true, true);
              }

              int len = data.Length;
              WeatherData[] wdata = new WeatherData[len];

              double min = double.MaxValue;
              double max = double.MinValue;

              // fill the array
              for (int i = 0; i < len; i++)
              {
            wdata[i] = new WeatherData(DateTime.Parse(data[i, 0]),
              double.Parse(data[i, "Max TemperatureF"]),
              double.Parse(data[i, "Mean TemperatureF"]),
              double.Parse(data[i, "Min TemperatureF"]));

              min = Math.Min(min, wdata[i].TMin);
              max = Math.Max(max, wdata[i].TMax);
              }

              if (len > 0)
              {
              chart.BeginUpdate();
              chart.Data.Children.Clear();
              chart.Data.ItemsSource = wdata;

              Style ss = (Style)Resources["sstyle"];

            // create data series
              XYDataSeries ds = new XYDataSeries(); ds.Label = "Minimum";
              ds.ValueBinding = new Binding("TMin");
              ds.XValueBinding = new Binding("DateTime");
              ds.SymbolStyle = ss;
              chart.Data.Children.Add(ds);

              ds = new XYDataSeries(); ds.Label = "Maximum";
              ds.ValueBinding = new Binding("TMax");
              ds.XValueBinding = new Binding("DateTime");
              ds.SymbolStyle = ss;
              chart.Data.Children.Add(ds);

            //ds = new XYDataSeries(); ds.Label = "Average";
            //ds.ValueBinding = new Binding("TAvg");
            //ds.XValueBinding = new Binding("DateTime");
            //ds.SymbolStyle = ss;
              //chart.Data.Children.Add(ds);

              chart.View.AxisX.Min = wdata[0].DateTime.ToOADate();
            chart.View.AxisX.Max = wdata[len - 1].DateTime.ToOADate();

              chart.View.AxisY.Min = min;
              chart.View.AxisY.Max = max;

              chart.EndUpdate();
              }

              WaitAndDisableAnimation();
        }