protected override void Init(GdiContainer mainContainer, GdiRectangle chartContainer) { base.Init(mainContainer, chartContainer); const int NumberOfColumns = 4; _categoryHeight = chartContainer.Size.Height / Categories.Length; _maxValue = DataSet.SelectMany(x => x.Data).Max(x => x) * 1.1f; _minValue = DataSet.SelectMany(x => x.Data).Min(x => x) * 1.1f; if (StepSize == 0) { var range = _maxValue - _minValue; if (range < NumberOfColumns) { StepSize = 1; } else { StepSize = (int)(range / NumberOfColumns); } } if (_minValue > 0) { _minValue = 0; } _widthUnit = chartContainer.Size.Width / (Math.Abs(_minValue) + _maxValue); _rootX = Padding.Left + (_widthUnit * Math.Abs(_minValue)); }
protected override void Init(GdiContainer mainContainer, GdiRectangle chartContainer) { base.Init(mainContainer, chartContainer); if (StepSize <= 0) { throw new ArgumentException("Invalid StepSize"); } if (StepSize <= 0 || Categories.Length < 3) { throw new ArgumentException("Invalid data"); } _maxRadius = Math.Min(chartContainer.Size.Width, chartContainer.Size.Height) / 2; _centerPoint = new PointF(Padding.Left + _maxRadius, Padding.Top + _maxRadius); var maxDataValue = MaxDataValue > 0 ? MaxDataValue : DataSets.SelectMany(x => x.Data).Max(); maxDataValue = (int)Math.Ceiling((double)maxDataValue / StepSize) * StepSize; // round it _numberOfSteps = (int)Math.Ceiling(maxDataValue / StepSize) + 1; // remove this variable _stepSizeInPixel = _maxRadius / _numberOfSteps; _unitPixel = _maxRadius / (maxDataValue + StepSize); }
protected override void Init(GdiContainer mainContainer, GdiRectangle chartContainer) { base.Init(mainContainer, chartContainer); _categoryHeight = chartContainer.Size.Height / Categories.Length; _widthUnit = chartContainer.Size.Width / 100; }
protected override void Init(GdiContainer mainContainer, GdiRectangle chartContainer) { base.Init(mainContainer, chartContainer); this.MainContainer.BackgroundColor = Color.Transparent; _chartRect = CalculateChartRect(); this.LegendWidth = _chartRect.Width; this.LegendHeight = this.Size.Height - this.Padding.Top - _chartRect.Height / 2 - 50; }
protected override void BuildComponents(GdiContainer mainContainer, GdiRectangle chartContainer) { base.BuildComponents(mainContainer, chartContainer); var rangeBar = AddRangeBar(chartContainer); AddRangeBarColumns(chartContainer, rangeBar); AddRangeBarLabels(chartContainer, rangeBar); }
protected override void Init(GdiContainer mainContainer, GdiRectangle chartContainer) { base.Init(mainContainer, chartContainer); if (Entries == null || Entries.Length == 0) { throw new ArgumentException("Invalid entries data"); } }
private void AddVerLabelAxis(GdiContainer mainContainer, GdiRectangle chartContainer) { mainContainer.AddChild(new GdiVerLabelAxis { Margin = new PointF(0, Padding.Top), Size = new SizeF(Padding.Left, chartContainer.Size.Height), Labels = Categories, LabelHeight = _categoryHeight, LabelOffsetX = Padding.Left - 10, Font = Font }); }
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); } } }
protected override void Init(GdiContainer mainContainer, GdiRectangle chartContainer) { base.Init(mainContainer, chartContainer); if (MaxValue <= 0 || MaxValue <= MinValue) { throw new ArgumentException("Invalid range value!"); } if (Entries == null || !Entries.Any()) { throw new ArgumentException("Invalid entries!"); } }
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); }
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 void AddHozLabelAxis(GdiContainer mainContainer, GdiRectangle chartContainer) { var leftToRightLabels = Enumerable.Range(0, 100 / StepSize + 1) .Select(x => string.Format(FormatAxisValue, x * StepSize)).ToArray(); mainContainer.AddChild(new GdiHozLabelAxis { Size = new SizeF(chartContainer.Size.Width, Padding.Bottom), Margin = new PointF(Padding.Left, this.Size.Height - Padding.Bottom), RootX = 0, LeftToRightLabels = leftToRightLabels, LabelWidth = _widthUnit * StepSize, Font = Font }); }
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); var table = new GdiDataGrid { Size = chartContainer.Size, LineColor = Color.Gray, Rows = Rows, Columns = Columns, MergedCells = MergedCells, Texts = Texts, TextColor = TextColor }; chartContainer.AddChild(table); }
private void AddHozLabelAxis(GdiContainer mainContainer, GdiRectangle chartContainer) { var leftToRightLabels = Enumerable.Range(0, (int)Math.Ceiling(_maxValue / StepSize)) .Select(x => string.Format(FormatAxisValue, x * StepSize)).ToArray(); var rightToLeftLabels = Enumerable.Range(0, (int)Math.Ceiling(Math.Abs(_minValue) / StepSize)) .Select(x => string.Format(FormatAxisValue, -x * StepSize)).ToArray(); mainContainer.AddChild(new GdiHozLabelAxis { Size = new SizeF(chartContainer.Size.Width, Padding.Bottom), Margin = new PointF(Padding.Left, this.Size.Height - Padding.Bottom), RootX = _rootX - Padding.Left, LeftToRightLabels = leftToRightLabels, RightToLeftLabels = rightToLeftLabels, LabelWidth = _widthUnit * StepSize, Font = Font }); }
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); }
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 }); } }
protected override void Init(GdiContainer mainContainer, GdiRectangle chartContainer) { base.Init(mainContainer, chartContainer); CategoryWidth = chartContainer.Size.Width / Categories.Length; _maxValue = DataSets.SelectMany(x => x.Data).Max(x => x) * (IsOneHundredPercentChart ? 1f : 1.1f); _minValue = DataSets.SelectMany(x => x.Data).Min(x => x) * (IsOneHundredPercentChart ? 1f : 1.1f); if (_minValue > 0) { _minValue = 0; } var maxLength = (Math.Abs(_minValue) + _maxValue); _heightUnit = maxLength == 0 ? 1 : chartContainer.Size.Height / maxLength; _rootY = Padding.Top + (_heightUnit * Math.Abs(_maxValue)); }
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); } }
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 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 }); } }
protected virtual void BuildComponents(GdiContainer mainContainer, GdiRectangle chartContainer) { if (Legend != null && Legend.Items == null) { CreateLegendItems(); } if (Legend != null && Legend.Items != null && Legend.Items.Any()) { mainContainer.AddChild(new GdiLegend { Margin = new PointF(this.Padding.Left, 10), VerticalAlignment = GdiSharp.Enum.GdiVerticalAlign.Bottom, Size = new SizeF( LegendWidth == 0 ? chartContainer.Size.Width : LegendWidth, LegendHeight == 0 ? Math.Max(GdiLegendItem.LineHeight, this.Padding.Bottom - 50) : LegendHeight), Legend = Legend }); } AddTitle(mainContainer); AddSubTitle(mainContainer); }
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); }