private void AddRangeBarLabels(GdiRectangle chartContainer, GdiRangeBar rangeBar) { var margin = new PointF(0, rangeBar.Margin.Y + rangeBar.Size.Height + 15); if (!string.IsNullOrWhiteSpace(LeftLabel)) { chartContainer.AddChild(new GdiText { TextColor = TextColor, Content = LeftLabel, Font = Font, Margin = margin }); } if (!string.IsNullOrWhiteSpace(CenterLabel)) { chartContainer.AddChild(new GdiText { TextColor = TextColor, Content = CenterLabel, Font = Font, HorizontalAlignment = GdiSharp.Enum.GdiHorizontalAlign.Center, Margin = margin }); } if (!string.IsNullOrWhiteSpace(RightLabel)) { chartContainer.AddChild(new GdiText { TextColor = TextColor, Content = RightLabel, Font = Font, HorizontalAlignment = GdiSharp.Enum.GdiHorizontalAlign.Right, Margin = margin, TextAlign = StringAlignment.Far }); } }
public override void BeforeRendering(Graphics graphics) { if (Rows == 0 || Columns == 0) { throw new ArgumentException("Rows and Columns can not be zero"); } base.BeforeRendering(graphics); var cellWidth = this.Size.Width / Columns; var cellHeight = this.Size.Height / Rows; for (int row = 0; row < Rows; row++) { for (int col = 0; col < Columns; col++) { var size = new SizeF(cellWidth, cellHeight); var margin = new PointF(col * cellWidth, row * cellHeight); var mergedCell = GetMergedCell(row, col); if (mergedCell != null) { size = new SizeF((mergedCell.ToCol - mergedCell.FromCol + 1) * cellWidth, (mergedCell.ToRow - mergedCell.FromRow + 1) * cellHeight); margin = new PointF(mergedCell.FromCol * cellWidth, mergedCell.FromRow * cellHeight); } else if (IsInMergedPositions(row, col)) { continue; } var cell = new GdiRectangle { Border = new Models.Border { Color = LineColor, Size = 1 }, Size = size, Margin = margin }; var text = new GdiText { Content = GetText(row, col), TextColor = TextColor, HorizontalAlignment = Enum.GdiHorizontalAlign.Center, VerticalAlignment = Enum.GdiVerticalAlign.Middle, TextAlign = StringAlignment.Center }; cell.AddChild(text); this.AddChild(cell); } } }
private void SetupContainer() { MainContainer = new GdiRectangle { Size = this.Size, BackgroundColor = Color.White }; ChartContainer = new GdiRectangle { Margin = new PointF(Padding.Left, Padding.Top), Size = new SizeF(Size.Width - Padding.Left - Padding.Right, Size.Height - Padding.Top - Padding.Bottom) }; MainContainer.AddChild(ChartContainer); }
private GdiRangeBar AddRangeBar(GdiRectangle chartContainer) { var barHeight = chartContainer.Size.Height - 60; var rangeBar = new GdiRangeBar { Size = new SizeF(chartContainer.Size.Width, barHeight), Margin = new PointF(0, 10), BackgroundColor = ColorTranslator.FromHtml("#123367"), CenterColor = ColorTranslator.FromHtml("#BDD2F3") }; chartContainer.AddChild(rangeBar); return(rangeBar); }
protected override void BuildComponents(GdiContainer mainContainer, GdiRectangle chartContainer) { base.BuildComponents(mainContainer, chartContainer); var table = new GdiDataGrid { Size = chartContainer.Size, LineColor = Color.Gray, Rows = Rows, Columns = Columns, MergedCells = MergedCells, Texts = Texts, TextColor = TextColor }; chartContainer.AddChild(table); }
protected override void BuildComponents(GdiContainer mainContainer, GdiRectangle chartContainer) { base.BuildComponents(mainContainer, chartContainer); var pie = new GdiPie { Diameter = chartContainer.Size.Height, Entries = Entries, IsDonut = IsDonut, HorizontalAlignment = GdiMapper.ToGdiHorizontalAlign(this.PieAlign), TextColor = TextColor, LabelFormat = LabelFormat, Font = Font }; chartContainer.AddChild(pie); }
protected override void BuildComponents(GdiContainer mainContainer, GdiRectangle chartContainer) { base.BuildComponents(mainContainer, chartContainer); // Add left, right captions const int RectWidth = 200; var rectTop = Padding.Top + _chartRect.Height / 2 + 10; if (!string.IsNullOrWhiteSpace(LeftCaption)) { var rect = new GdiRectangle { Margin = new PointF(_chartRect.Left - RectWidth / 2, rectTop), Size = new SizeF(RectWidth, 30) }; mainContainer.AddChild(rect); rect.AddChild(new GdiText { Font = SlimFont.Default, Content = LeftCaption, HorizontalAlignment = GdiSharp.Enum.GdiHorizontalAlign.Center, VerticalAlignment = GdiSharp.Enum.GdiVerticalAlign.Middle, TextAlign = StringAlignment.Center }); } if (!string.IsNullOrWhiteSpace(RightCaption)) { var rect = new GdiRectangle { Margin = new PointF(Padding.Left + _chartRect.Width - RectWidth / 2, rectTop), Size = new SizeF(RectWidth, 30) }; mainContainer.AddChild(rect); rect.AddChild(new GdiText { Font = SlimFont.Default, Content = RightCaption, HorizontalAlignment = GdiSharp.Enum.GdiHorizontalAlign.Center, VerticalAlignment = GdiSharp.Enum.GdiVerticalAlign.Middle, TextAlign = StringAlignment.Center }); } }
public override void BeforeRendering(Graphics graphics) { base.BeforeRendering(graphics); if (Legend == null || Legend.Items == null || !Legend.Items.Any()) { return; } var size = GetLegendItemsSize(graphics); var itemContainer = new GdiRectangle { Size = size, HorizontalAlignment = GdiSharp.Enum.GdiHorizontalAlign.Center, Margin = new PointF(0, 10) }; var legendSlimFont = new SlimFont(Legend.FontName, Legend.FontSize); using (var font = new Font(Legend.FontName, Legend.FontSize)) { var x = 0f; var line = 0; foreach (var item in Legend.Items) { var textWidth = graphics.MeasureString(item.Text, font).Width; var itemWidth = GdiLegendItem.RectWidth + GdiLegendItem.GapWidth + textWidth + GdiLegendItem.GapWidth; if (x + itemWidth > itemContainer.Size.Width + 1) { x = 0f; line++; } itemContainer.AddChild(new GdiLegendItem { Margin = new PointF(x, line * GdiLegendItem.LineHeight), Size = new SizeF(itemWidth, GdiLegendItem.RectHeight), Text = item.Text, RectangleColor = item.Color, Font = legendSlimFont }); x += itemWidth; } } this.AddChild(itemContainer); }
private void AddChartArea(GdiRectangle chartArea) { if (ChartGridModel == null) { ChartGridModel = new ChartGridModel { LineColor = Color.LightGray }; } _barChartArea = new GdiStackedColumn100ChartArea { Size = chartArea.Size, CellSize = new SizeF(_categoryWidth, _heightUnit * StepSize), ChartGridModel = ChartGridModel, BarSettingModel = BarSetting, DataSet = DataSet }; chartArea.AddChild(_barChartArea); }
private void AddRangeBarColumns(GdiRectangle chartContainer, GdiRangeBar rangeBar) { var onePercentWidth = rangeBar.Size.Width / 100; // bar is 100% width var columnHeight = rangeBar.Size.Height + 30; var columnTop = rangeBar.Margin.Y - ((columnHeight - rangeBar.Size.Height) / 2); var rangeValue = MaxValue - MinValue; foreach (var entry in Entries) { var x = (entry.Value - MinValue) / rangeValue * 100 * onePercentWidth; var column = new GdiColumn { BackgroundColor = entry.Color, Size = new SizeF(10, columnHeight), Margin = new PointF(x - 5, columnTop) }; chartContainer.AddChild(column); } }
private void AddBarSeries(DataSeries series, int offsetY) { var y = (CellSize.Height / 2) + offsetY; foreach (var value in series.Data) { var length = WidthUnit * value; var bar = new GdiRectangle { Size = new SizeF(Math.Abs(length), BarSettingModel.Size), Margin = new PointF(0, y), BackgroundColor = series.Color, }; var text = new GdiText { Margin = new PointF(bar.Size.Width + 2, 0), Content = string.Format(BarSettingModel.FormatValue, value), Font = BarSettingModel.ValueFont, TextColor = Color.Gray, VerticalAlignment = GdiSharp.Enum.GdiVerticalAlign.Middle }; if (length > 0) { RightPanel.AddChild(bar); } else if (length < 0) { LeftPanel.AddChild(bar); bar.HorizontalAlignment = GdiSharp.Enum.GdiHorizontalAlign.Right; text.HorizontalAlignment = GdiSharp.Enum.GdiHorizontalAlign.Right; } bar.AddChild(text); y += CellSize.Height; } }
public override void BeforeRendering(Graphics graphics) { base.BeforeRendering(graphics); if (Values.Length != Colors.Length) { throw new ArgumentException("Values and Colors must have the same number of items."); } var size = this.Size; var pixelUnit = size.Width / 100; var sum = this.Values.Sum(); var x = 0f; var font = SlimFont.Default; font.Size = 10; for (int i = 0; i < Values.Length; i++) { var percent = Values[i] / sum * 100; var width = percent * pixelUnit; var section = new GdiRectangle { BackgroundColor = Colors[i], Margin = new PointF(x, 0), Size = new SizeF(width, size.Height) }; var text = new GdiText { Content = string.Format(TextFormat, percent), HorizontalAlignment = GdiSharp.Enum.GdiHorizontalAlign.Center, VerticalAlignment = GdiSharp.Enum.GdiVerticalAlign.Middle, Font = font, TextColor = Color.Black }; section.AddChild(text); this.AddChild(section); x += width; } }
private void AddChartArea(GdiRectangle chartArea) { if (ChartGridModel == null) { ChartGridModel = new ChartGridModel { LineColor = Color.LightGray }; } _barChartArea = new GdiBarChartArea { // base LeftPanelWidth = _rootX - Padding.Left, Size = chartArea.Size, CellSize = new SizeF(_widthUnit * StepSize, _categoryHeight), ChartGridModel = ChartGridModel, // GdiBarChartDataArea BarSettingModel = BarSetting, DataSet = DataSet, WidthUnit = _widthUnit }; chartArea.AddChild(_barChartArea); }
public override void BeforeRendering(Graphics graphics) { base.BeforeRendering(graphics); if (Values.Length != Colors.Length || Values.Length != TextColors.Length) { throw new ArgumentException("Values and Colors must have the same number of items."); } var sum = this.Values.Sum(); if (sum == 0) { return; } var size = this.Size; var pixelUnit = size.Height / 100; var y = size.Height; var font = SlimFont.Default; font.Size = 10; for (int i = 0; i < Values.Length; i++) { var percent = Values[i] / sum * 100; if (percent <= 0.1) { continue; } var height = percent * pixelUnit; var section = new GdiRectangle { BackgroundColor = Colors[i], Margin = new PointF(0, y - height), Size = new SizeF(size.Width, height) }; if (i < Values.Length - 1) { section.AddChild(new GdiHozLine { Length = size.Width, BackgroundColor = Color.White, LineHeight = 2 }); } var text = new GdiText { Content = string.Format(TextFormat, percent), HorizontalAlignment = GdiSharp.Enum.GdiHorizontalAlign.Center, VerticalAlignment = GdiSharp.Enum.GdiVerticalAlign.Middle, Font = font, TextColor = TextColors[i] }; // move the text outside the column if (percent <= 2) { text.Margin = new PointF(size.Width, 0); text.HorizontalAlignment = GdiSharp.Enum.GdiHorizontalAlign.Left; text.TextColor = Color.Black; } section.AddChild(text); this.AddChild(section); y -= height; } }