示例#1
0
        public void LoadTableAndShowInLineChart()
        {
            kx.c c         = new kx.c("localhost", 5000);
            var  g         = 30;
            var  obj       = c.k("monthCur", g) as Flip;
            var  window    = new Window();
            var  lineChart = new LineChart();

            for (int i = 1; i < obj.x.Length; i++)
            {
                var name   = obj.x[i];
                var values = (obj.y[i] as long[]).Select((v, index) => new KeyValuePair <int, long>(index * g, v));
                var line   = new LineSeries();
                line.Title = name;
                line.SetBinding(LineSeries.ItemsSourceProperty, new Binding()
                {
                    Source = values
                });
                line.IndependentValuePath = "Key";
                line.DependentValuePath   = "Value";
                line.DataPointStyle       = null;
                line.AnimationSequence    = AnimationSequence.FirstToLast;
                lineChart.AddLine(line);
            }
            Assert.IsNotNull(obj);
            window.Content = lineChart;
            window.ShowDialog();
        }
        } // constructor

        public void AddNewCurves(CurvePoint[][] xCurvePoints, double xYShift)
        {
            if (!Dispatcher.CheckAccess())
            {
                Action lAction = () => { AddNewCurves(xCurvePoints, xYShift); };
                App.Current.Dispatcher.BeginInvoke(lAction);
                return;
            }

            // find the Y axis
            LinearAxis lYAxis = null;
            foreach (IAxis lAxis in _MainWindow.myChart.Axes)
            {
                if (lAxis.Orientation != AxisOrientation.Y) continue;
                lYAxis = lAxis as LinearAxis;
            }

            int lCount = xCurvePoints.GetUpperBound(0);
            LineSeries[] lLineSeries = new LineSeries[lCount];
            for (int x = 0, n = lCount; x < n; x++)
            {
                LineSeries lLine = new LineSeries();
                lLineSeries[x] = lLine;
                lLine.DependentRangeAxis = lYAxis;

                lLine.Title = "manually added curve";
                lLine.SetBinding(LineSeries.ItemsSourceProperty, new Binding());

                lLine.IndependentValueBinding = new Binding("Time");
                lLine.DependentValueBinding = new Binding("CurveId");

                Style lLineStyle = new Style(typeof(Polyline));
                //lLineStyle.Setters.Add(new Setter(Polyline.StrokeStartLineCapProperty, PenLineCap.Flat));
                //lLineStyle.Setters.Add(new Setter(Polyline.StrokeEndLineCapProperty, PenLineCap.Triangle));

                Style lPointStyle = new Style(typeof(DataPoint));

                if (xYShift == 0.0)
                {
                    lLineStyle.Setters.Add(new Setter(Polyline.StrokeThicknessProperty, 3.0));
                    lPointStyle.Setters.Add(new Setter(DataPoint.WidthProperty, 0.0));
                    lPointStyle.Setters.Add(new Setter(DataPoint.BackgroundProperty, new SolidColorBrush(Colors.LightGreen)));
                }
                else
                {
                    lLineStyle.Setters.Add(new Setter(Polyline.StrokeThicknessProperty, 1.0));
                    lPointStyle.Setters.Add(new Setter(DataPoint.WidthProperty, 0.0));
                    lPointStyle.Setters.Add(new Setter(DataPoint.BackgroundProperty, new SolidColorBrush(Colors.Black)));
                }
                lLine.PolylineStyle = lLineStyle;
                lLine.DataPointStyle = lPointStyle;

                xCurvePoints[x][0].CurveId -= xYShift;
                xCurvePoints[x][1].CurveId -= xYShift;
                lLine.ItemsSource = xCurvePoints[x];
                _MainWindow.myChart.Series.Add(lLine);
            }
        } //
        private void UpdateChart()
        {
            foreach (SeriesData seriesData in Controller.Graph.Series.Where(s => s.Visible))
            {
                var series = new LineSeries
                {
                    DependentValuePath = "Amount",
                    IndependentValuePath = "Month",
                    IsSelectionEnabled = true,
                    DataContext = seriesData
                };

                var plotsBinding = new Binding
                {
                    Path = new PropertyPath("Plots")
                };
                series.SetBinding(DataPointSeries.ItemsSourceProperty, plotsBinding);

                var titleBinding = new Binding
                {
                    Path = new PropertyPath("SeriesName")
                };
                series.SetBinding(Series.TitleProperty, titleBinding);

                var visibilityBinding = new Binding
                {
                    Path = new PropertyPath("Visible"),
                    Converter = new BooleanToVisibilityConverter()
                };
                series.SetBinding(VisibilityProperty, visibilityBinding);

                series.SelectionChanged += SeriesOnSelectionChanged;

                this.Chart.Series.Add(series);
            }
        }
示例#4
0
        public Chart(IWpfVisualizerData data, string bindingName, bool isProgressChart)
        {
            InitializeComponent();

            var binding = new Binding(bindingName);

            binding.Source = data;
            LineSeries.SetBinding(Series.FillProperty, binding);

            if (isProgressChart)
            {   //Disable drawing of AxisY separator
                binding = new Binding();
                AxisYSeparator.SetBinding(Separator.IsEnabledProperty, binding);
                AxisYSeparator.SetValue(Separator.StrokeThicknessProperty, 0d);
            }

            DataContext = data;
        }
示例#5
0
        private static LineSeries ProvideLineSeries(PropertyInfo propertyInfo, string dependentValuePath,
                                                    string independentValuePath)
        {
            var series = new LineSeries();

            series.SetBinding(DataPointSeries.ItemsSourceProperty, propertyInfo.GetBinding());
            series.IndependentValuePath = independentValuePath;
            series.DependentValuePath   = dependentValuePath;

            series.Unloaded += (o, e) =>
            {
                var control = o as LineSeries;
                if (control == null)
                {
                    return;
                }

                BindingOperations.ClearAllBindings(control);
            };

            return(series);
        }
        private void DrawCurve_WPF_Runtime(Chart lChart, AxisPointDateTime lAxisPointDateTimeX, AxisPointLinear lAxisPointLinearY)
        {
            PriceClusterSimple lDataPoint = new PriceClusterSimple(lAxisPointDateTimeX.MouseAxisValueAbsolute, lAxisPointLinearY.MouseAxisValueAbsolute);

            if (ManualPoints != null)
            {
                if (_DrawNewLine)
                {
                    _DrawNewLine = false;
                    ManualPoints.Clear();
                    ManualPoints.Add(lDataPoint); // from
                    ManualPoints.Add(lDataPoint); // to
                }
                else
                {
                    ManualPoints.RemoveAt(1);
                    ManualPoints.Add(lDataPoint); // to
                }
                return;
            }

            ManualPoints = new ObservableCollection<PriceClusterSimple>();
            ManualPoints.Add(lDataPoint);
            ManualPoints.Add(lDataPoint);
            LineSeries lNewLineSeries = new LineSeries();
            lNewLineSeries.Title = "manually added curve";
            lNewLineSeries.SetBinding(LineSeries.ItemsSourceProperty, new Binding());
            lNewLineSeries.ItemsSource = ManualPoints;
            lNewLineSeries.IndependentValueBinding = new Binding("Date");
            lNewLineSeries.DependentValueBinding = new Binding("Price");
            lNewLineSeries.DependentRangeAxis = lAxisPointLinearY.Axis;
            Setter lHeightSetter = new Setter(FrameworkElement.HeightProperty, 0.0);
            Setter lWidthSetter = new Setter(FrameworkElement.WidthProperty, 0.0);
            Setter lColor = new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Black));
            Style lStyle = new Style(typeof(Control));
            lNewLineSeries.DataPointStyle = lStyle;
            lStyle.Setters.Add(lHeightSetter);
            lStyle.Setters.Add(lWidthSetter);
            lStyle.Setters.Add(lColor);
            lChart.Series.Add(lNewLineSeries);
        } //
        void viewModel_SelectedParameterIDChanged(object sender, EventArgs e)
        {
            FlightAnalysisSubLiteViewModel viewModel = this.GetViewModel();
            if (viewModel == null || viewModel.ChartViewModel == null
                || this.DataLoader == null)
                return;

            var tempArray = new string[] { viewModel.SelectedParameterID };

            this.DataLoader.LoadRawDataAsync(tempArray);
            var tempGroup = AircraftDataAnalysisModel1.WinRT.DataModel.FlightAnalysisChartGroupFactory.CalculateBindingGroups(tempArray);
            //Group must be only one
            var gpName = tempGroup.First().Key;

            var rawDatas = DataLoader.GetRawData(viewModel.SelectedParameterID);
            Dictionary<int, SimpleDataPoint> pointMapper = new Dictionary<int, SimpleDataPoint>();
            foreach (var item in viewModel.ChartViewModel)
            {
                if (!pointMapper.ContainsKey(item.Second))
                {
                    pointMapper.Add(item.Second, item);
                }
            }

            foreach (var raw in rawDatas)
            {
                if (pointMapper.ContainsKey(raw.Second))
                {
                    pointMapper[raw.Second].Value = raw.Values[0];
                }
            }

            var Xaxis1 = this.tracker1.Axes["xm1XAxis1"] as CategoryXAxis;
            var Yaxis1 = this.tracker1.Axes["xm1YAxis1"] as NumericYAxis;
            var Xaxis2 = this.tracker1.Axes["xm1XAxis2"] as CategoryXAxis;
            var Yaxis2 = this.tracker1.Axes["xm1YAxis2"] as NumericYAxis;
            //Left YAxis    
            var xaxis = Xaxis1;
            var yaxis = Yaxis1;

            if (gpName != viewModel.Group1ID)
            {                //Right YAxis
                xaxis = Xaxis2;
                yaxis = Yaxis2;
            }

            Series temp = this.tracker1.Series["addParamSerie"];
            if (temp != null)
                this.tracker1.Series.Remove(temp);

            LineSeries serie = new LineSeries() { Name = "addParamSerie" };
            serie.XAxis = xaxis;
            serie.ItemsSource = viewModel.ChartViewModel;
            serie.SetBinding(LineSeries.VisibilityProperty, new Binding()
            {
                Path = new PropertyPath("CompareParameterSerieVisibility"),
                Source = viewModel
            });
            serie.YAxis = yaxis;
            serie.Title = ApplicationContext.Instance.GetFlightParameterCaption(viewModel.SelectedParameterID);
            serie.Legend = this.TitleLegend;
            serie.MarkerType = MarkerType.None;
            serie.ValueMemberPath = "Value";
            serie.DataContext = viewModel;

            this.tracker1.Series.Add(serie);
        }