示例#1
0
        private void AddItemFactory(FrameworkElementFactory parent, CityDataItem item)
        {
            var itemFactory = new FrameworkElementFactory(typeof(TextBlock));

            itemFactory.SetValue(TextBlock.TextProperty, item.Name.ToUpper());
            itemFactory.SetValue(TextBlock.FontSizeProperty, 13.0);
            itemFactory.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
            itemFactory.SetValue(TextBlock.ForegroundProperty, new SolidColorBrush(Color.FromRgb(186, 28, 245)));
            parent.AppendChild(itemFactory);
        }
示例#2
0
        public void GetTemperatureData(string[] cities, bool monthly = false, int count = 30, bool isFahrenheit = false)
        {
            _data = new List <CityDataItem>();
            var startDate = new DateTime(2019, 1, 1);

            foreach (string city in cities)
            {
                var dataItem = new CityDataItem()
                {
                    Name = city
                };
                for (int i = 0; i < count; i++)
                {
                    var      temp = new Temperature();
                    DateTime date;
                    if (monthly)
                    {
                        date = startDate.AddMonths(i);
                    }
                    else
                    {
                        date = startDate.AddDays(i);
                    }
                    temp.Date = date;
                    if (date.Month <= 8)
                    {
                        temp.HighTemp = rnd.Next(3 * date.Month, 8 * date.Month);
                    }
                    else
                    {
                        temp.HighTemp = rnd.Next((13 - date.Month - 2) * date.Month, (13 - date.Month) * date.Month);
                    }
                    temp.Precipitation = (date.Month < 4 || date.Month > 8) ? rnd.Next(100, 150) : rnd.Next(150, 200);
                    if (isFahrenheit)
                    {
                        temp.HighTemp = temp.HighTemp * 1.8 + 32;
                    }
                    dataItem.Data.Add(temp);
                }
                _data.Add(dataItem);
            }
        }
示例#3
0
        private void SetupAnnotationData(double temp, int itemIndex, int index, CityDataItem item, PointCollection points, bool isMinAnnotation = true)
        {
            //Create canvas
            var canvasFactory = CreateCanvasFactory();

            //Polygon
            AddPolygonFactory(canvasFactory, points);

            //Create Stack Panel Factory
            var spFactory = CreateStackPanelFactory();

            //Temperature
            AddTemperatureFactory(spFactory, temp);
            //Text Block Temperature
            AddTextBlockFactory(spFactory, isMinAnnotation ? "Minimum Temperature" : "Maximum Temperature");
            //Item Name
            AddItemFactory(spFactory, item);
            canvasFactory.AppendChild(spFactory);

            //Create Data Template
            var dataTemplate = new DataTemplate
            {
                VisualTree = canvasFactory
            };

            dataTemplate.Seal();

            var serie = flexChart.Series[index];
            var xVals = serie.GetValues(1);
            var yVals = serie.GetValues(0);

            var locationX = xVals == null?serie.AxisX.Convert(itemIndex) : serie.AxisX.Convert(xVals[itemIndex]);

            var locationY = yVals == null?serie.AxisY.Convert(itemIndex) : serie.AxisY.Convert(yVals[itemIndex]);

            if (isMinAnnotation)
            {
                locationX -= 60;
                locationY -= 80;
            }
            else
            {
                locationX -= 60;
                locationY += 20;
            }
            //Create TemplateAnnotation
            var annoTemplate = new Template
            {
                Style = new ChartStyle()
                {
                    Fill   = new SolidColorBrush(Colors.White),
                    Stroke = new SolidColorBrush(Colors.Gray)
                },
                Attachment   = AnnotationAttachment.Absolute,
                SeriesIndex  = index,
                PointIndex   = itemIndex,
                AnnoTemplate = dataTemplate,
                Location     = new Point(locationX, locationY)
            };

            annotationLayer.Annotations.Add(annoTemplate);
        }