Пример #1
0
        private void UpdatePlot()
        {
            var pm = new PlotModel(this.year.ToString(), "data from gapminder.org")
            {
                LegendPosition = LegendPosition.RightBottom
            };
            var ss = new ScatterSeries
            {
                MarkerType            = MarkerType.Circle,
                MarkerFill            = OxyColors.Transparent,
                MarkerStroke          = OxyColors.Blue,
                MarkerStrokeThickness = 1
            };

            var piX     = typeof(Statistics).GetProperty("GdpPerCapitaPpp");
            var piY     = typeof(Statistics).GetProperty("LifeExpectancyAtBirth");
            var piSize  = typeof(Statistics).GetProperty("Population");
            var piColor = typeof(Statistics).GetProperty("GeographicRegion");

            foreach (var kvp in Countries)
            {
                Country country = kvp.Value;
                double  x       = country.FindValue(year, piX);
                double  y       = country.FindValue(year, piY);
                double  size    = country.FindValue(year, piSize);

                if (double.IsNaN(x) || double.IsNaN(y))
                {
                    continue;
                }
                ss.Points.Add(new ScatterPoint(x, y, double.NaN, double.NaN, country.Name));

                //double radius = 4;
                //if (!double.IsNaN(size))
                //    radius = Math.Sqrt(size)*0.1;
                //if (radius < 4) radius = 4;
                //if (radius > 40) radius = 40;
                //ss.MarkerSizes.Add(radius);
                //   Debug.WriteLine(countryName+": "+stats.Population);
            }
            pm.Series.Add(ss);
            if (SelectedCountry != null)
            {
                var ls = new LineSeries(SelectedCountry.Name);
                ls.LineJoin = OxyPenLineJoin.Bevel;
                foreach (var p in SelectedCountry.Statistics)
                {
                    if (double.IsNaN(p.GdpPerCapitaPpp) || double.IsNaN(p.LifeExpectancyAtBirth))
                    {
                        continue;
                    }
                    ls.Points.Add(new DataPoint(p.GdpPerCapitaPpp, p.LifeExpectancyAtBirth));
                }
                pm.Series.Add(ls);
                var    ss2 = new ScatterSeries();
                double x   = SelectedCountry.FindValue(year, piX);
                double y   = SelectedCountry.FindValue(year, piY);
                ss2.Points.Add(new ScatterPoint(x, y, 10));
                ss2.MarkerFill = OxyColor.FromAColor(120, OxyColors.Red);
                ss2.MarkerType = MarkerType.Circle;
                pm.Series.Add(ss2);
            }
            pm.Axes.Add(new LinearAxis(AxisPosition.Left, 19, 87, "Life expectancy (years)"));
            pm.Axes.Add(new LogarithmicAxis(AxisPosition.Bottom, 200, 90000, "Income per person (GDP/capita, PPP$ inflation-adjusted)"));
            PlotModel = pm;
        }