private void Primary_LabelCreated(object sender, ChartAxisLabelEventArgs e) { DateTime baseDate = new DateTime(1899, 12, 30); var date = baseDate.AddDays(e.Position); if (date.Month != month) { ChartAxisLabelStyle labelStyle = new ChartAxisLabelStyle(); labelStyle.LabelFormat = "MMM-dd"; labelStyle.FontSize = 9; labelStyle.FontAttributes = FontAttributes.Bold; e.LabelStyle = labelStyle; month = date.Month; } else { ChartAxisLabelStyle labelStyle = new ChartAxisLabelStyle(); labelStyle.LabelFormat = "dd"; e.LabelStyle = labelStyle; if (Device.RuntimePlatform == Device.WPF) { labelStyle.FontSize = 12; } } }
public StarsTrendsChart(IMainThread mainThread) : base(mainThread, TrendsPageAutomationIds.StarsChart) { var primaryAxisLabelStyle = new ChartAxisLabelStyle { FontSize = 9, FontFamily = FontFamilyConstants.RobotoRegular, Margin = new Thickness(2, 4, 2, 0) }.DynamicResource(ChartLabelStyle.TextColorProperty, nameof(BaseTheme.ChartAxisTextColor)); var axisLineStyle = new ChartLineStyle() { StrokeWidth = 1.51 }.DynamicResource(ChartLineStyle.StrokeColorProperty, nameof(BaseTheme.ChartAxisLineColor)); PrimaryAxis = new DateTimeAxis { IntervalType = DateTimeIntervalType.Months, Interval = 1, RangePadding = DateTimeRangePadding.Round, LabelStyle = primaryAxisLabelStyle, AxisLineStyle = axisLineStyle, MajorTickStyle = new ChartAxisTickStyle { StrokeColor = Color.Transparent }, ShowMajorGridLines = false, }; PrimaryAxis.SetBinding(DateTimeAxis.MinimumProperty, nameof(TrendsViewModel.MinDailyStarsDate)); PrimaryAxis.SetBinding(DateTimeAxis.MaximumProperty, nameof(TrendsViewModel.MaxDailyStarsDate)); var secondaryAxisMajorTickStyle = new ChartAxisTickStyle().DynamicResource(ChartAxisTickStyle.StrokeColorProperty, nameof(BaseTheme.ChartAxisLineColor)); var secondaryAxisLabelStyle = new ChartAxisLabelStyle { FontSize = 12, FontFamily = FontFamilyConstants.RobotoRegular, }.DynamicResource(ChartLabelStyle.TextColorProperty, nameof(BaseTheme.ChartAxisTextColor)); SecondaryAxis = new NumericalAxis { LabelStyle = secondaryAxisLabelStyle, AxisLineStyle = axisLineStyle, MajorTickStyle = secondaryAxisMajorTickStyle, ShowMajorGridLines = false, }.Bind(NumericalAxis.MinimumProperty, nameof(TrendsViewModel.MinDailyStarsValue)) .Bind(NumericalAxis.MaximumProperty, nameof(TrendsViewModel.MaxDailyStarsValue)) .Bind(NumericalAxis.IntervalProperty, nameof(TrendsViewModel.StarsChartYAxisInterval)); StarsSeries = new TrendsAreaSeries(TrendsChartTitleConstants.StarsTitle, nameof(DailyStarsModel.LocalDay), nameof(DailyStarsModel.TotalStars), nameof(BaseTheme.CardStarsStatsIconColor)); StarsSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyStarsList)); StarsSeries.PropertyChanged += HandleStarSeriesPropertyChanged; Series = new ChartSeriesCollection { StarsSeries }; this.SetBinding(IsVisibleProperty, nameof(TrendsViewModel.IsStarsChartVisible)); }
private void Primary_LabelCreated(object sender, ChartAxisLabelEventArgs e) { DateTime baseDate = new DateTime(1899, 12, 30); var date = baseDate.AddDays(e.Position); if (date.Month != month) { ChartAxisLabelStyle labelStyle = new ChartAxisLabelStyle(); labelStyle.LabelFormat = "MMM-dd"; labelStyle.Font = Font.SystemFontOfSize(9, FontAttributes.Bold); e.LabelStyle = labelStyle; month = date.Month; } else { ChartAxisLabelStyle labelStyle = new ChartAxisLabelStyle(); labelStyle.LabelFormat = "dd"; e.LabelStyle = labelStyle; } }
public Chart() { Margin = 0; ChartPadding = new Thickness(0, 24, 0, 4); BackgroundColor = Color.Transparent; AutomationId = TrendsPageAutomationIds.TrendsChart; TotalViewsSeries = new TrendsAreaSeries(TrendsChartConstants.TotalViewsTitle, nameof(DailyViewsModel.LocalDay), nameof(DailyViewsModel.TotalViews), nameof(BaseTheme.TotalViewsColor)); TotalViewsSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyViewsList)); TotalViewsSeries.SetBinding(ChartSeries.IsVisibleProperty, nameof(TrendsViewModel.IsViewsSeriesVisible)); TotalUniqueViewsSeries = new TrendsAreaSeries(TrendsChartConstants.UniqueViewsTitle, nameof(DailyViewsModel.LocalDay), nameof(DailyViewsModel.TotalUniqueViews), nameof(BaseTheme.TotalUniqueViewsColor)); TotalUniqueViewsSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyViewsList)); TotalUniqueViewsSeries.SetBinding(ChartSeries.IsVisibleProperty, nameof(TrendsViewModel.IsUniqueViewsSeriesVisible)); TotalClonesSeries = new TrendsAreaSeries(TrendsChartConstants.TotalClonesTitle, nameof(DailyClonesModel.LocalDay), nameof(DailyClonesModel.TotalClones), nameof(BaseTheme.TotalClonesColor)); TotalClonesSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyClonesList)); TotalClonesSeries.SetBinding(ChartSeries.IsVisibleProperty, nameof(TrendsViewModel.IsClonesSeriesVisible)); TotalUniqueClonesSeries = new TrendsAreaSeries(TrendsChartConstants.UniqueClonesTitle, nameof(DailyClonesModel.LocalDay), nameof(DailyClonesModel.TotalUniqueClones), nameof(BaseTheme.TotalUniqueClonesColor)); TotalUniqueClonesSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyClonesList)); TotalUniqueClonesSeries.SetBinding(ChartSeries.IsVisibleProperty, nameof(TrendsViewModel.IsUniqueClonesSeriesVisible)); ChartBehaviors = new ChartBehaviorCollection { new ChartZoomPanBehavior(), new ChartTrackballBehavior() }; Series = new ChartSeriesCollection { TotalViewsSeries, TotalUniqueViewsSeries, TotalClonesSeries, TotalUniqueClonesSeries, }; var primaryAxisLabelStyle = new ChartAxisLabelStyle { FontSize = 9, FontFamily = FontFamilyConstants.RobotoRegular, Margin = new Thickness(2, 4, 2, 0) }; primaryAxisLabelStyle.SetDynamicResource(ChartLabelStyle.TextColorProperty, nameof(BaseTheme.ChartAxisTextColor)); var axisLineStyle = new ChartLineStyle() { StrokeWidth = 1.51 }; axisLineStyle.SetDynamicResource(ChartLineStyle.StrokeColorProperty, nameof(BaseTheme.ChartAxisLineColor)); PrimaryAxis = new DateTimeAxis { AutomationId = TrendsPageAutomationIds.TrendsChartPrimaryAxis, IntervalType = DateTimeIntervalType.Days, Interval = 1, RangePadding = DateTimeRangePadding.Round, LabelStyle = primaryAxisLabelStyle, AxisLineStyle = axisLineStyle, MajorTickStyle = new ChartAxisTickStyle { StrokeColor = Color.Transparent }, ShowMajorGridLines = false, }; PrimaryAxis.SetBinding(DateTimeAxis.MinimumProperty, nameof(TrendsViewModel.MinDateValue)); PrimaryAxis.SetBinding(DateTimeAxis.MaximumProperty, nameof(TrendsViewModel.MaxDateValue)); var secondaryAxisMajorTickStyle = new ChartAxisTickStyle(); secondaryAxisMajorTickStyle.SetDynamicResource(ChartAxisTickStyle.StrokeColorProperty, nameof(BaseTheme.ChartAxisLineColor)); var secondaryAxisLabelStyle = new ChartAxisLabelStyle { FontSize = 12, FontFamily = FontFamilyConstants.RobotoRegular, }; secondaryAxisLabelStyle.SetDynamicResource(ChartLabelStyle.TextColorProperty, nameof(BaseTheme.ChartAxisTextColor)); SecondaryAxis = new NumericalAxis { AutomationId = TrendsPageAutomationIds.TrendsChartSecondaryAxis, LabelStyle = secondaryAxisLabelStyle, AxisLineStyle = axisLineStyle, MajorTickStyle = secondaryAxisMajorTickStyle, ShowMajorGridLines = false }; SecondaryAxis.SetBinding(NumericalAxis.MinimumProperty, nameof(TrendsViewModel.DailyViewsClonesMinValue)); SecondaryAxis.SetBinding(NumericalAxis.MaximumProperty, nameof(TrendsViewModel.DailyViewsClonesMaxValue)); }
public GitHubTrendsChart() { TotalViewsSeries = new TrendsAreaSeries("Views", nameof(DailyViewsModel.LocalDay), nameof(DailyViewsModel.TotalViews), ColorConstants.DarkestBlue); TotalViewsSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyViewsList)); TotalUniqueViewsSeries = new TrendsAreaSeries("Unique Views", nameof(DailyViewsModel.LocalDay), nameof(DailyViewsModel.TotalUniqueViews), ColorConstants.MediumBlue); TotalUniqueViewsSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyViewsList)); TotalClonesSeries = new TrendsAreaSeries("Clones", nameof(DailyClonesModel.LocalDay), nameof(DailyClonesModel.TotalClones), ColorConstants.DarkNavyBlue); TotalClonesSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyClonesList)); TotalUniqueClonesSeries = new TrendsAreaSeries("Unique Clones", nameof(DailyClonesModel.LocalDay), nameof(DailyClonesModel.TotalUniqueClones), ColorConstants.LightNavyBlue); TotalUniqueClonesSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyClonesList)); this.SetBinding(IsVisibleProperty, nameof(TrendsViewModel.IsChartVisible)); ChartBehaviors = new ChartBehaviorCollection { new ChartZoomPanBehavior(), new ChartTrackballBehavior() }; Series = new ChartSeriesCollection { TotalViewsSeries, TotalUniqueViewsSeries, TotalClonesSeries, TotalUniqueClonesSeries }; Legend = new ChartLegend { DockPosition = LegendPlacement.Bottom, ToggleSeriesVisibility = true, IconWidth = 20, IconHeight = 20, LabelStyle = new ChartLegendLabelStyle { TextColor = ColorConstants.DarkNavyBlue } }; var axisLabelStyle = new ChartAxisLabelStyle { TextColor = ColorConstants.DarkNavyBlue, FontSize = 14 }; var axisLineStyle = new ChartLineStyle { StrokeColor = ColorConstants.LightNavyBlue }; PrimaryAxis = new DateTimeAxis { IntervalType = DateTimeIntervalType.Days, Interval = 1, RangePadding = DateTimeRangePadding.Round, LabelStyle = axisLabelStyle, AxisLineStyle = axisLineStyle, MajorTickStyle = new ChartAxisTickStyle { StrokeColor = Color.Transparent }, ShowMajorGridLines = false }; PrimaryAxis.SetBinding(DateTimeAxis.MinimumProperty, nameof(TrendsViewModel.MinDateValue)); PrimaryAxis.SetBinding(DateTimeAxis.MaximumProperty, nameof(TrendsViewModel.MaxDateValue)); SecondaryAxis = new NumericalAxis { LabelStyle = axisLabelStyle, AxisLineStyle = axisLineStyle, MajorTickStyle = new ChartAxisTickStyle { StrokeColor = ColorConstants.LightNavyBlue }, ShowMajorGridLines = false }; SecondaryAxis.SetBinding(NumericalAxis.MinimumProperty, nameof(TrendsViewModel.DailyViewsClonesMinValue)); SecondaryAxis.SetBinding(NumericalAxis.MaximumProperty, nameof(TrendsViewModel.DailyViewsClonesMaxValue)); BackgroundColor = Color.Transparent; ChartPadding = new Thickness(0, 5, 0, 0); Margin = Device.RuntimePlatform is Device.iOS ? new Thickness(0, 5, 0, 15) : new Thickness(0, 5, 0, 0); }
public override View GetSampleContent(Context context) { var chart = new SfChart(context); chart.Title.Text = "Food Production - 2017"; chart.SetBackgroundColor(Color.White); chart.Scroll += (sender, e) => { month = int.MaxValue; }; DateTimeAxis dateTimeAxis = new DateTimeAxis(); dateTimeAxis.Title.Text = "Production Across Years"; dateTimeAxis.ZoomFactor = 0.2f; dateTimeAxis.ZoomPosition = 0.6f; dateTimeAxis.LabelCreated += (sender, e) => { var date = DateTime.Parse(e.AxisLabel.LabelContent.ToString()); if (date.Month != month) { ChartAxisLabelStyle labelStyle = new ChartAxisLabelStyle(); labelStyle.LabelFormat = "MMM-dd"; labelStyle.TextSize = 9; labelStyle.Typeface = Typeface.DefaultBold; e.AxisLabel.LabelStyle = labelStyle; month = date.Month; } else { ChartAxisLabelStyle labelStyle = new ChartAxisLabelStyle(); labelStyle.LabelFormat = "dd"; e.AxisLabel.LabelStyle = labelStyle; } }; dateTimeAxis.EdgeLabelsDrawingMode = EdgeLabelsDrawingMode.Shift; chart.PrimaryAxis = dateTimeAxis; var numericalAxis = new NumericalAxis(); numericalAxis.Title.Text = "Growth (In Metric Tons)"; chart.SecondaryAxis = numericalAxis; FastLineSeries lineSeries = new FastLineSeries(); lineSeries.ColorModel.ColorPalette = ChartColorPalette.Natural; lineSeries.ItemsSource = Data.GetDateTimeValue(); lineSeries.XBindingPath = "Date"; lineSeries.YBindingPath = "YValue"; lineSeries.TooltipEnabled = true; chart.Series.Add(lineSeries); ChartZoomPanBehavior zoomPan = new ChartZoomPanBehavior(); zoomPan.SelectionZoomingEnabled = false; zoomPan.ZoomMode = ZoomMode.X; chart.Behaviors.Add(zoomPan); return(chart); }
public GitHubTrendsChart() { AutomationId = TrendsPageAutomationIds.TrendsChart; TotalViewsSeries = new TrendsAreaSeries("Views", nameof(DailyViewsModel.LocalDay), nameof(DailyViewsModel.TotalViews), nameof(BaseTheme.TotalViewsColor), TrendsPageAutomationIds.TotalViewsSeries); TotalViewsSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyViewsList)); TotalUniqueViewsSeries = new TrendsAreaSeries("Unique Views", nameof(DailyViewsModel.LocalDay), nameof(DailyViewsModel.TotalUniqueViews), nameof(BaseTheme.TotalUniqueViewsColor), TrendsPageAutomationIds.TotalUniqueViewsSeries); TotalUniqueViewsSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyViewsList)); TotalClonesSeries = new TrendsAreaSeries("Clones", nameof(DailyClonesModel.LocalDay), nameof(DailyClonesModel.TotalClones), nameof(BaseTheme.TotalClonesColor), TrendsPageAutomationIds.TotalClonesSeries); TotalClonesSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyClonesList)); TotalUniqueClonesSeries = new TrendsAreaSeries("Unique Clones", nameof(DailyClonesModel.LocalDay), nameof(DailyClonesModel.TotalUniqueClones), nameof(BaseTheme.TotalUniqueClonesColor), TrendsPageAutomationIds.TotalUniqueClonesSeries); TotalUniqueClonesSeries.SetBinding(ChartSeries.ItemsSourceProperty, nameof(TrendsViewModel.DailyClonesList)); this.SetBinding(IsVisibleProperty, nameof(TrendsViewModel.IsChartVisible)); ChartBehaviors = new ChartBehaviorCollection { new ChartZoomPanBehavior(), new ChartTrackballBehavior() }; Series = new ChartSeriesCollection { TotalViewsSeries, TotalUniqueViewsSeries, TotalClonesSeries, TotalUniqueClonesSeries }; var chartLegendLabelStyle = new ChartLegendLabelStyle(); chartLegendLabelStyle.SetDynamicResource(ChartLegendLabelStyle.TextColorProperty, nameof(BaseTheme.ChartAxisTextColor)); Legend = new ChartLegend { AutomationId = TrendsPageAutomationIds.TrendsChartLegend, DockPosition = LegendPlacement.Bottom, ToggleSeriesVisibility = true, IconWidth = 20, IconHeight = 20, LabelStyle = chartLegendLabelStyle }; var axisLabelStyle = new ChartAxisLabelStyle { FontSize = 14 }; axisLabelStyle.SetDynamicResource(ChartAxisLabelStyle.TextColorProperty, nameof(BaseTheme.ChartAxisTextColor)); var axisLineStyle = new ChartLineStyle(); axisLineStyle.SetDynamicResource(ChartLineStyle.StrokeColorProperty, nameof(BaseTheme.ChartAxisLineColor)); PrimaryAxis = new DateTimeAxis { AutomationId = TrendsPageAutomationIds.TrendsChartPrimaryAxis, IntervalType = DateTimeIntervalType.Days, Interval = 1, RangePadding = DateTimeRangePadding.Round, LabelStyle = axisLabelStyle, AxisLineStyle = axisLineStyle, MajorTickStyle = new ChartAxisTickStyle { StrokeColor = Color.Transparent }, ShowMajorGridLines = false }; PrimaryAxis.SetBinding(DateTimeAxis.MinimumProperty, nameof(TrendsViewModel.MinDateValue)); PrimaryAxis.SetBinding(DateTimeAxis.MaximumProperty, nameof(TrendsViewModel.MaxDateValue)); var secondaryAxisMajorTickStyle = new ChartAxisTickStyle(); secondaryAxisMajorTickStyle.SetDynamicResource(ChartAxisTickStyle.StrokeColorProperty, nameof(BaseTheme.ChartAxisLineColor)); SecondaryAxis = new NumericalAxis { AutomationId = TrendsPageAutomationIds.TrendsChartSecondaryAxis, LabelStyle = axisLabelStyle, AxisLineStyle = axisLineStyle, MajorTickStyle = secondaryAxisMajorTickStyle, ShowMajorGridLines = false }; SecondaryAxis.SetBinding(NumericalAxis.MinimumProperty, nameof(TrendsViewModel.DailyViewsClonesMinValue)); SecondaryAxis.SetBinding(NumericalAxis.MaximumProperty, nameof(TrendsViewModel.DailyViewsClonesMaxValue)); BackgroundColor = Color.Transparent; ChartPadding = new Thickness(0, 5, 0, 0); }