# ChartLegacy ## Description Simple and flexible charting component for data visualization, which supports eight chart types: bar, line, area, pie, bubble, radar, polar, and scatter. ## Parameters | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | SetupCompletedCallback | `EventCallback` | | This event is fired when the chart has been setup through interop and the JavaScript chart object is available. Use this callback if you need to setup custom JavaScript options or register plugins. | | Config | `BitChartLegacyConfigBase` | | Gets or sets the configuration of the chart. | | Width | `int?` | null | Gets or sets the width of the canvas HTML element. | | Height | `int?` | null | Gets or sets the height of the canvas HTML element. | | AriaLabel | `string?` | null | Gets or sets the accessible label for the component, used by assistive technologies. | | Class | `string?` | null | Gets or sets the CSS class name(s) to apply to the rendered element. | | Dir | `BitDir?` | null | Gets or sets the text directionality for the component's content. | | HtmlAttributes | `Dictionary<string, object>` | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. | | Id | `string?` | null | Gets or sets the unique identifier for the component's root element. | | IsEnabled | `bool` | true | Gets or sets a value indicating whether the component is enabled and can respond to user interaction. | | Style | `string?` | null | Gets or sets the CSS style string to apply to the rendered element. | | TabIndex | `string?` | null | Gets or sets the tab order index for the component when navigating with the keyboard. | | Visibility | `BitVisibility` | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. | ## Public Members | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | UniqueId | `Guid` | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. | | RootElement | `ElementReference` | | Gets the reference to the root HTML element associated with this component. | ## Enums ### BitVisibility Enum | Name | Value | Description | | :--- | :--- | :---------- | | Visible | 0 | The content of the component is visible. | | Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). | | Collapsed | 2 | The component is hidden (display:none). | ### BitDir Enum | Name | Value | Description | | :--- | :--- | :---------- | | Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). | | Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). | | Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. | ## Sub Classes ### BitChartLegacyConfigBase Properties | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | Type | `BitChartLegacyChartType` | null | Gets the type of chart this config is for. | | CanvasId | `string` | Guid.NewGuid().ToString() | Gets the id for the html canvas element associated with this chart. | | Plugins | `IList<object>` | new List<object>() | Gets the list of inline plugins for this chart. | ## Examples \n**Bar Chart**: ```razor Randomize Data Add Dataset Remove Dataset Add Data Remove Data ``` ```csharp private const int INITAL_COUNT = 5; private BitChartLegacy _chart = default!; private BitChartLegacyBarConfig _config = default!; protected override void OnInitialized() { _config = new BitChartLegacyBarConfig { Options = new BitChartLegacyBarOptions { Responsive = true, Title = new BitChartLegacyOptionsTitle { Display = true, Text = "BitChartLegacy bar Chart" }, Scales = new BitChartLegacyBarScales { XAxes = [ new BitChartLegacyBarCategoryAxis { GridLines = new BitChartLegacyGridLines { Color = "gray" } } ], YAxes = [ new BitChartLegacyLinearCartesianAxis { GridLines = new BitChartLegacyGridLines { Color = "gray" } } ] } } }; System.Drawing.Color color = BitChartLegacyDemoColors.All[new Random().Next(0, BitChartLegacyDemoColors.All.Count - 1)]; var dataset = new BitChartLegacyBarDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT)) { Label = "Dataset 1", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(System.Drawing.Color.FromArgb(128, color)), }; _config.Data.Labels.AddRange(BitChartLegacyDemoUtils.Months.Take(INITAL_COUNT)); _config.Data.Datasets.Add(dataset); } private void RandomizeBarData() { foreach (IDataset dataset in _config.Data.Datasets) { int count = dataset.Count; dataset.Clear(); for (int i = 0; i < count; i++) { if (BitChartLegacyDemoUtils._rng.NextDouble() < 0.2) { dataset.Add(0); } else { dataset.Add(BitChartLegacyDemoUtils.RandomScalingFactor()); } } } _chart.Update(); } private void AddBarDataset() { System.Drawing.Color color = BitChartLegacyDemoColors.All[_config.Data.Datasets.Count % BitChartLegacyDemoColors.All.Count]; IDataset dataset = new BitChartLegacyBarDataset(BitChartLegacyDemoUtils.RandomScalingFactor(_config.Data.Labels.Count)) { Label = $"Dataset {_config.Data.Datasets.Count + 1}", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(System.Drawing.Color.FromArgb(128, color)), BorderColor = BitChartLegacyColorUtil.FromDrawingColor(color), BorderWidth = 1 }; _config.Data.Datasets.Add(dataset); _chart.Update(); } private void RemoveBarDataset() { IList datasets = _config.Data.Datasets; if (datasets.Count == 0) return; datasets.RemoveAt(datasets.Count - 1); _chart.Update(); } private void AddBarData() { if (_config.Data.Datasets.Count == 0) return; string month = BitChartLegacyDemoUtils.Months[_config.Data.Labels.Count % BitChartLegacyDemoUtils.Months.Count]; _config.Data.Labels.Add(month); foreach (IDataset dataset in _config.Data.Datasets) { dataset.Add(BitChartLegacyDemoUtils.RandomScalingFactor()); } _chart.Update(); } private void RemoveBarData() { if (_config.Data.Datasets.Count == 0 || _config.Data.Labels.Count == 0) { return; } _config.Data.Labels.RemoveAt(_config.Data.Labels.Count - 1); foreach (IDataset dataset in _config.Data.Datasets) { dataset.RemoveAt(dataset.Count - 1); } _chart.Update(); } public static class BitChartLegacyDemoColors { private static readonly Lazy> _all = new(() => [ Red, Orange, Yellow, Green, Blue, Purple, Grey ]); public static IReadOnlyList All => _all.Value; public static readonly System.Drawing.Color Red = System.Drawing.Color.FromArgb(255, 99, 132); public static readonly System.Drawing.Color Orange = System.Drawing.Color.FromArgb(255, 159, 64); public static readonly System.Drawing.Color Yellow = System.Drawing.Color.FromArgb(255, 205, 86); public static readonly System.Drawing.Color Green = System.Drawing.Color.FromArgb(75, 192, 192); public static readonly System.Drawing.Color Blue = System.Drawing.Color.FromArgb(54, 162, 235); public static readonly System.Drawing.Color Purple = System.Drawing.Color.FromArgb(153, 102, 255); public static readonly System.Drawing.Color Grey = System.Drawing.Color.FromArgb(201, 203, 207); } public static class BitChartLegacyDemoUtils { public static readonly Random _rng = new(); public static IReadOnlyList Months { get; } = new ReadOnlyCollection( [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]); private static int RandomScalingFactorThreadUnsafe(int min, int max) => _rng.Next(min, max); public static int RandomScalingFactor() { lock (_rng) { return RandomScalingFactorThreadUnsafe(0, 100); } } public static IEnumerable RandomScalingFactor(int count, int min = 0, int max = 100) { int[] factors = new int[count]; lock (_rng) { for (int i = 0; i < count; i++) { factors[i] = RandomScalingFactorThreadUnsafe(min, max); } } return factors; } public static IEnumerable GetNextDays(int count) { DateTime now = DateTime.Now; DateTime[] factors = new DateTime[count]; for (int i = 0; i < factors.Length; i++) { factors[i] = now.AddDays(i); } return factors; } } public static class IListExtensions { public static void AddRange(this IList list, IEnumerable items) { if (list == null) throw new ArgumentNullException(nameof(list)); if (items == null) throw new ArgumentNullException(nameof(items)); if (list is List asList) { asList.AddRange(items); } else { foreach (T item in items) { list.Add(item); } } } } ``` \n**Horizontal Bar Chart**: ```razor ``` ```csharp private const int INITAL_COUNT = 5; private BitChartLegacy _chart = default!; private BitChartLegacyBarConfig _config = default!; protected override void OnInitialized() { _config = new BitChartLegacyBarConfig(horizontal: true) { Options = new BitChartLegacyBarOptions { Responsive = true, Legend = new BitChartLegacyLegend { Position = BitChartLegacyPosition.Right }, Title = new BitChartLegacyOptionsTitle { Display = true, Text = "BitChartLegacy Horizontal Bar Chart" }, Scales = new BitChartLegacyBarScales { XAxes = [ new BitChartLegacyLinearCartesianAxis { GridLines = new BitChartLegacyGridLines { Color = "gray" } } ], YAxes = [ new BitChartLegacyBarCategoryAxis { GridLines = new BitChartLegacyGridLines { Color = "gray" } } ] } } }; IDataset dataset1 = new BitChartLegacyBarDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT, -100), horizontal: true) { Label = "My first dataset", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(System.Drawing.Color.FromArgb(128, BitChartLegacyDemoColors.Red)), BorderColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Red), BorderWidth = 1 }; IDataset dataset2 = new BitChartLegacyBarDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT, -100), horizontal: true) { Label = "My second dataset", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(System.Drawing.Color.FromArgb(128, BitChartLegacyDemoColors.Blue)), BorderColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Blue), BorderWidth = 1 }; _config.Data.Labels.AddRange(BitChartLegacyDemoUtils.Months.Take(INITAL_COUNT)); _config.Data.Datasets.Add(dataset1); _config.Data.Datasets.Add(dataset2); } public static class BitChartLegacyDemoColors { private static readonly Lazy> _all = new(() => [ Red, Orange, Yellow, Green, Blue, Purple, Grey ]); public static IReadOnlyList All => _all.Value; public static readonly System.Drawing.Color Red = System.Drawing.Color.FromArgb(255, 99, 132); public static readonly System.Drawing.Color Orange = System.Drawing.Color.FromArgb(255, 159, 64); public static readonly System.Drawing.Color Yellow = System.Drawing.Color.FromArgb(255, 205, 86); public static readonly System.Drawing.Color Green = System.Drawing.Color.FromArgb(75, 192, 192); public static readonly System.Drawing.Color Blue = System.Drawing.Color.FromArgb(54, 162, 235); public static readonly System.Drawing.Color Purple = System.Drawing.Color.FromArgb(153, 102, 255); public static readonly System.Drawing.Color Grey = System.Drawing.Color.FromArgb(201, 203, 207); } public static class BitChartLegacyDemoUtils { public static readonly Random _rng = new(); public static IReadOnlyList Months { get; } = new ReadOnlyCollection( [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]); private static int RandomScalingFactorThreadUnsafe(int min, int max) => _rng.Next(min, max); public static int RandomScalingFactor() { lock (_rng) { return RandomScalingFactorThreadUnsafe(0, 100); } } public static IEnumerable RandomScalingFactor(int count, int min = 0, int max = 100) { int[] factors = new int[count]; lock (_rng) { for (int i = 0; i < count; i++) { factors[i] = RandomScalingFactorThreadUnsafe(min, max); } } return factors; } public static IEnumerable GetNextDays(int count) { DateTime now = DateTime.Now; DateTime[] factors = new DateTime[count]; for (int i = 0; i < factors.Length; i++) { factors[i] = now.AddDays(i); } return factors; } } public static class IListExtensions { public static void AddRange(this IList list, IEnumerable items) { if (list == null) throw new ArgumentNullException(nameof(list)); if (items == null) throw new ArgumentNullException(nameof(items)); if (list is List asList) { asList.AddRange(items); } else { foreach (T item in items) { list.Add(item); } } } } ``` \n**Stacked Bar Chart**: ```razor ``` ```csharp private const int INITAL_COUNT = 5; private BitChartLegacy _chart = default!; private BitChartLegacyBarConfig _config = default!; protected override void OnInitialized() { _config = new BitChartLegacyBarConfig { Options = new BitChartLegacyBarOptions() { Responsive = true, Title = new BitChartLegacyOptionsTitle { Display = true, Text = "BitChartLegacy stacked bar Chart" }, Tooltips = new BitChartLegacyTooltips { Mode = BitChartLegacyInteractionMode.Index, Intersect = false }, Scales = new BitChartLegacyBarScales { XAxes = [ new BitChartLegacyBarCategoryAxis { Stacked = true, GridLines = new BitChartLegacyGridLines { Color = "gray" } } ], YAxes = [ new BitChartLegacyBarLinearCartesianAxis { Stacked = true, GridLines = new BitChartLegacyGridLines { Color = "gray" } } ] } } }; IDataset dataset1 = new BitChartLegacyBarDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT)) { Label = "Dataset 1", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Red) }; IDataset dataset2 = new BitChartLegacyBarDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT)) { Label = "Dataset 2", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Blue) }; IDataset dataset3 = new BitChartLegacyBarDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT)) { Label = "Dataset 3", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Green) }; _config.Data.Datasets.Add(dataset1); _config.Data.Datasets.Add(dataset2); _config.Data.Datasets.Add(dataset3); _config.Data.Labels.AddRange(BitChartLegacyDemoUtils.Months.Take(INITAL_COUNT)); } public static class BitChartLegacyDemoColors { private static readonly Lazy> _all = new(() => [ Red, Orange, Yellow, Green, Blue, Purple, Grey ]); public static IReadOnlyList All => _all.Value; public static readonly System.Drawing.Color Red = System.Drawing.Color.FromArgb(255, 99, 132); public static readonly System.Drawing.Color Orange = System.Drawing.Color.FromArgb(255, 159, 64); public static readonly System.Drawing.Color Yellow = System.Drawing.Color.FromArgb(255, 205, 86); public static readonly System.Drawing.Color Green = System.Drawing.Color.FromArgb(75, 192, 192); public static readonly System.Drawing.Color Blue = System.Drawing.Color.FromArgb(54, 162, 235); public static readonly System.Drawing.Color Purple = System.Drawing.Color.FromArgb(153, 102, 255); public static readonly System.Drawing.Color Grey = System.Drawing.Color.FromArgb(201, 203, 207); } public static class BitChartLegacyDemoUtils { public static readonly Random _rng = new(); public static IReadOnlyList Months { get; } = new ReadOnlyCollection( [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]); private static int RandomScalingFactorThreadUnsafe(int min, int max) => _rng.Next(min, max); public static int RandomScalingFactor() { lock (_rng) { return RandomScalingFactorThreadUnsafe(0, 100); } } public static IEnumerable RandomScalingFactor(int count, int min = 0, int max = 100) { int[] factors = new int[count]; lock (_rng) { for (int i = 0; i < count; i++) { factors[i] = RandomScalingFactorThreadUnsafe(min, max); } } return factors; } public static IEnumerable GetNextDays(int count) { DateTime now = DateTime.Now; DateTime[] factors = new DateTime[count]; for (int i = 0; i < factors.Length; i++) { factors[i] = now.AddDays(i); } return factors; } } public static class IListExtensions { public static void AddRange(this IList list, IEnumerable items) { if (list == null) throw new ArgumentNullException(nameof(list)); if (items == null) throw new ArgumentNullException(nameof(items)); if (list is List asList) { asList.AddRange(items); } else { foreach (T item in items) { list.Add(item); } } } } ``` \n**Linear Line Chart**: ```razor ``` ```csharp private const int INITAL_COUNT = 5; private BitChartLegacy _chart = default!; private BitChartLegacyLineConfig _config = default!; protected override void OnInitialized() { _config = new BitChartLegacyLineConfig { Options = new BitChartLegacyLineOptions { Responsive = true, Title = new BitChartLegacyOptionsTitle { Display = true, Text = "BitChartLegacy Line Chart" }, Tooltips = new BitChartLegacyTooltips { Mode = BitChartLegacyInteractionMode.Nearest, Intersect = true }, Hover = new BitChartLegacyHover { Mode = BitChartLegacyInteractionMode.Nearest, Intersect = true }, Scales = new BitChartLegacyScales { XAxes = [ new BitChartLegacyCategoryAxis { ScaleLabel = new BitChartLegacyScaleLabel { LabelString = "Month" }, GridLines = new BitChartLegacyGridLines { Color = "gray" } } ], YAxes = [ new BitChartLegacyLinearCartesianAxis { ScaleLabel = new BitChartLegacyScaleLabel { LabelString = "Value" }, GridLines = new BitChartLegacyGridLines { Color = "gray" } } ] } } }; IDataset dataset1 = new BitChartLegacyLineDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT)) { Label = "My first dataset", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Red), BorderColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Red), Fill = BitChartLegacyFillingMode.Disabled }; IDataset dataset2 = new BitChartLegacyLineDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT)) { Label = "My second dataset", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Blue), BorderColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Blue), Fill = BitChartLegacyFillingMode.Disabled }; _config.Data.Labels.AddRange(BitChartLegacyDemoUtils.Months.Take(INITAL_COUNT)); _config.Data.Datasets.Add(dataset1); _config.Data.Datasets.Add(dataset2); } public static class BitChartLegacyDemoColors { private static readonly Lazy> _all = new(() => [ Red, Orange, Yellow, Green, Blue, Purple, Grey ]); public static IReadOnlyList All => _all.Value; public static readonly System.Drawing.Color Red = System.Drawing.Color.FromArgb(255, 99, 132); public static readonly System.Drawing.Color Orange = System.Drawing.Color.FromArgb(255, 159, 64); public static readonly System.Drawing.Color Yellow = System.Drawing.Color.FromArgb(255, 205, 86); public static readonly System.Drawing.Color Green = System.Drawing.Color.FromArgb(75, 192, 192); public static readonly System.Drawing.Color Blue = System.Drawing.Color.FromArgb(54, 162, 235); public static readonly System.Drawing.Color Purple = System.Drawing.Color.FromArgb(153, 102, 255); public static readonly System.Drawing.Color Grey = System.Drawing.Color.FromArgb(201, 203, 207); } public static class BitChartLegacyDemoUtils { public static readonly Random _rng = new(); public static IReadOnlyList Months { get; } = new ReadOnlyCollection( [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]); private static int RandomScalingFactorThreadUnsafe(int min, int max) => _rng.Next(min, max); public static int RandomScalingFactor() { lock (_rng) { return RandomScalingFactorThreadUnsafe(0, 100); } } public static IEnumerable RandomScalingFactor(int count, int min = 0, int max = 100) { int[] factors = new int[count]; lock (_rng) { for (int i = 0; i < count; i++) { factors[i] = RandomScalingFactorThreadUnsafe(min, max); } } return factors; } public static IEnumerable GetNextDays(int count) { DateTime now = DateTime.Now; DateTime[] factors = new DateTime[count]; for (int i = 0; i < factors.Length; i++) { factors[i] = now.AddDays(i); } return factors; } } public static class IListExtensions { public static void AddRange(this IList list, IEnumerable items) { if (list == null) throw new ArgumentNullException(nameof(list)); if (items == null) throw new ArgumentNullException(nameof(items)); if (list is List asList) { asList.AddRange(items); } else { foreach (T item in items) { list.Add(item); } } } } ``` \n**Pie Chart**: ```razor Randomize Data Add Dataset Remove Dataset ``` ```csharp private const int INITAL_COUNT = 5; private BitChartLegacy _chart = default!; private BitChartLegacyPieConfig _config = default!; protected override void OnInitialized() { _config = new BitChartLegacyPieConfig { Options = new BitChartLegacyPieOptions { Responsive = true, Title = new BitChartLegacyOptionsTitle { Display = true, Text = "BitChartLegacy Pie Chart" } } }; var dataset = new BitChartLegacyPieDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT)) { BackgroundColor = BitChartLegacyDemoColors.All.Take(INITAL_COUNT).Select(color => BitChartLegacyColorUtil.FromDrawingColor(color)).ToArray() }; _config.Data.Labels.AddRange(BitChartLegacyDemoUtils.Months.Take(INITAL_COUNT)); _config.Data.Datasets.Add(dataset); } private void RandomizePieData() { foreach (IDataset dataset in _config.Data.Datasets) { int count = dataset.Count; dataset.Clear(); for (int i = 0; i < count; i++) { if (BitChartLegacyDemoUtils._rng.NextDouble() < 0.2) { dataset.Add(0); } else { dataset.Add(BitChartLegacyDemoUtils.RandomScalingFactor()); } } } _chart.Update(); } private void AddPieDataset() { int count = _config.Data.Labels.Count; var dataset = new BitChartLegacyPieDataset(BitChartLegacyDemoUtils.RandomScalingFactor(count, -100, 100)) { BackgroundColor = BitChartLegacyDemoColors.All.Take(count).Select(color => BitChartLegacyColorUtil.FromDrawingColor(color)).ToArray() }; _config.Data.Datasets.Add(dataset); _chart.Update(); } private void RemovePieDataset() { IList datasets = _config.Data.Datasets; if (datasets.Count == 0) return; datasets.RemoveAt(0); _chart.Update(); } public static class BitChartLegacyDemoColors { private static readonly Lazy> _all = new(() => [ Red, Orange, Yellow, Green, Blue, Purple, Grey ]); public static IReadOnlyList All => _all.Value; public static readonly System.Drawing.Color Red = System.Drawing.Color.FromArgb(255, 99, 132); public static readonly System.Drawing.Color Orange = System.Drawing.Color.FromArgb(255, 159, 64); public static readonly System.Drawing.Color Yellow = System.Drawing.Color.FromArgb(255, 205, 86); public static readonly System.Drawing.Color Green = System.Drawing.Color.FromArgb(75, 192, 192); public static readonly System.Drawing.Color Blue = System.Drawing.Color.FromArgb(54, 162, 235); public static readonly System.Drawing.Color Purple = System.Drawing.Color.FromArgb(153, 102, 255); public static readonly System.Drawing.Color Grey = System.Drawing.Color.FromArgb(201, 203, 207); } public static class BitChartLegacyDemoUtils { public static readonly Random _rng = new(); public static IReadOnlyList Months { get; } = new ReadOnlyCollection( [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]); private static int RandomScalingFactorThreadUnsafe(int min, int max) => _rng.Next(min, max); public static int RandomScalingFactor() { lock (_rng) { return RandomScalingFactorThreadUnsafe(0, 100); } } public static IEnumerable RandomScalingFactor(int count, int min = 0, int max = 100) { int[] factors = new int[count]; lock (_rng) { for (int i = 0; i < count; i++) { factors[i] = RandomScalingFactorThreadUnsafe(min, max); } } return factors; } public static IEnumerable GetNextDays(int count) { DateTime now = DateTime.Now; DateTime[] factors = new DateTime[count]; for (int i = 0; i < factors.Length; i++) { factors[i] = now.AddDays(i); } return factors; } } public static class IListExtensions { public static void AddRange(this IList list, IEnumerable items) { if (list == null) throw new ArgumentNullException(nameof(list)); if (items == null) throw new ArgumentNullException(nameof(items)); if (list is List asList) { asList.AddRange(items); } else { foreach (T item in items) { list.Add(item); } } } } ``` \n**Doughnut Chart**: ```razor ``` ```csharp private const int INITAL_COUNT = 5; private BitChartLegacy _chart = default!; private BitChartLegacyPieConfig _config = default!; protected override void OnInitialized() { _config = new BitChartLegacyPieConfig(useDoughnutType: true) { Options = new BitChartLegacyPieOptions { Responsive = true, Title = new BitChartLegacyOptionsTitle { Display = true, Text = "BitChartLegacy Doughnut Chart" } } }; BitChartLegacyPieDataset dataset = new BitChartLegacyPieDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT)) { BackgroundColor = BitChartLegacyDemoColors.All.Take(INITAL_COUNT).Select(c => BitChartLegacyColorUtil.FromDrawingColor(System.Drawing.Color.FromArgb(220, c))).ToArray() }; _config.Data.Labels.AddRange(BitChartLegacyDemoUtils.Months.Take(INITAL_COUNT)); _config.Data.Datasets.Add(dataset); } public static class BitChartLegacyDemoColors { private static readonly Lazy> _all = new(() => [ Red, Orange, Yellow, Green, Blue, Purple, Grey ]); public static IReadOnlyList All => _all.Value; public static readonly System.Drawing.Color Red = System.Drawing.Color.FromArgb(255, 99, 132); public static readonly System.Drawing.Color Orange = System.Drawing.Color.FromArgb(255, 159, 64); public static readonly System.Drawing.Color Yellow = System.Drawing.Color.FromArgb(255, 205, 86); public static readonly System.Drawing.Color Green = System.Drawing.Color.FromArgb(75, 192, 192); public static readonly System.Drawing.Color Blue = System.Drawing.Color.FromArgb(54, 162, 235); public static readonly System.Drawing.Color Purple = System.Drawing.Color.FromArgb(153, 102, 255); public static readonly System.Drawing.Color Grey = System.Drawing.Color.FromArgb(201, 203, 207); } public static class BitChartLegacyDemoUtils { public static readonly Random _rng = new(); public static IReadOnlyList Months { get; } = new ReadOnlyCollection( [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]); private static int RandomScalingFactorThreadUnsafe(int min, int max) => _rng.Next(min, max); public static int RandomScalingFactor() { lock (_rng) { return RandomScalingFactorThreadUnsafe(0, 100); } } public static IEnumerable RandomScalingFactor(int count, int min = 0, int max = 100) { int[] factors = new int[count]; lock (_rng) { for (int i = 0; i < count; i++) { factors[i] = RandomScalingFactorThreadUnsafe(min, max); } } return factors; } public static IEnumerable GetNextDays(int count) { DateTime now = DateTime.Now; DateTime[] factors = new DateTime[count]; for (int i = 0; i < factors.Length; i++) { factors[i] = now.AddDays(i); } return factors; } } public static class IListExtensions { public static void AddRange(this IList list, IEnumerable items) { if (list == null) throw new ArgumentNullException(nameof(list)); if (items == null) throw new ArgumentNullException(nameof(items)); if (list is List asList) { asList.AddRange(items); } else { foreach (T item in items) { list.Add(item); } } } } ``` \n**PolarArea Chart**: ```razor Randomize Data Add Dataset Remove Dataset ``` ```csharp private const int INITAL_COUNT = 5; private BitChartLegacy _chart = default!; private BitChartLegacyPolarAreaConfig _config = default!; protected override void OnInitialized() { _config = new BitChartLegacyPolarAreaConfig { Options = new BitChartLegacyPolarAreaOptions { Responsive = true, Title = new BitChartLegacyOptionsTitle { Display = true, Text = "BitChartLegacy PolarArea Chart" }, Scale = new BitChartLegacyLinearRadialAxis { GridLines = new BitChartLegacyGridLines { Color = "gray" } } } }; var dataset = new BitChartLegacyPolarAreaDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT)) { BackgroundColor = BitChartLegacyDemoColors.All.Take(INITAL_COUNT).Select(color => BitChartLegacyColorUtil.FromDrawingColor(color)).ToArray() }; _config.Data.Labels.AddRange(BitChartLegacyDemoUtils.Months.Take(INITAL_COUNT)); _config.Data.Datasets.Add(dataset); } private void RandomizePolarAreaData() { foreach (IDataset dataset in _config.Data.Datasets) { int count = dataset.Count; dataset.Clear(); for (int i = 0; i < count; i++) { if (BitChartLegacyDemoUtils._rng.NextDouble() < 0.2) { dataset.Add(0); } else { dataset.Add(BitChartLegacyDemoUtils.RandomScalingFactor()); } } } _chart.Update(); } private void AddPolarAreaDataset() { int count = _config.Data.Labels.Count; BitChartLegacyPolarAreaDataset dataset = new BitChartLegacyPolarAreaDataset(BitChartLegacyDemoUtils.RandomScalingFactor(count, -100, 100)) { BackgroundColor = BitChartLegacyDemoColors.All.Take(count).Select(color => BitChartLegacyColorUtil.FromDrawingColor(color)).ToArray() }; _config.Data.Datasets.Add(dataset); _chart.Update(); } private void RemovePolarAreaDataset() { IList datasets = _config.Data.Datasets; if (datasets.Count == 0) return; datasets.RemoveAt(datasets.Count - 1); _chart.Update(); } public static class BitChartLegacyDemoColors { private static readonly Lazy> _all = new(() => [ Red, Orange, Yellow, Green, Blue, Purple, Grey ]); public static IReadOnlyList All => _all.Value; public static readonly System.Drawing.Color Red = System.Drawing.Color.FromArgb(255, 99, 132); public static readonly System.Drawing.Color Orange = System.Drawing.Color.FromArgb(255, 159, 64); public static readonly System.Drawing.Color Yellow = System.Drawing.Color.FromArgb(255, 205, 86); public static readonly System.Drawing.Color Green = System.Drawing.Color.FromArgb(75, 192, 192); public static readonly System.Drawing.Color Blue = System.Drawing.Color.FromArgb(54, 162, 235); public static readonly System.Drawing.Color Purple = System.Drawing.Color.FromArgb(153, 102, 255); public static readonly System.Drawing.Color Grey = System.Drawing.Color.FromArgb(201, 203, 207); } public static class BitChartLegacyDemoUtils { public static readonly Random _rng = new(); public static IReadOnlyList Months { get; } = new ReadOnlyCollection( [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]); private static int RandomScalingFactorThreadUnsafe(int min, int max) => _rng.Next(min, max); public static int RandomScalingFactor() { lock (_rng) { return RandomScalingFactorThreadUnsafe(0, 100); } } public static IEnumerable RandomScalingFactor(int count, int min = 0, int max = 100) { int[] factors = new int[count]; lock (_rng) { for (int i = 0; i < count; i++) { factors[i] = RandomScalingFactorThreadUnsafe(min, max); } } return factors; } public static IEnumerable GetNextDays(int count) { DateTime now = DateTime.Now; DateTime[] factors = new DateTime[count]; for (int i = 0; i < factors.Length; i++) { factors[i] = now.AddDays(i); } return factors; } } public static class IListExtensions { public static void AddRange(this IList list, IEnumerable items) { if (list == null) throw new ArgumentNullException(nameof(list)); if (items == null) throw new ArgumentNullException(nameof(items)); if (list is List asList) { asList.AddRange(items); } else { foreach (T item in items) { list.Add(item); } } } } ``` \n**Time Cartesian Axis**: ```razor Randomize Data Add Dataset Remove Dataset Add Data Remove Data ``` ```csharp private const int INITAL_COUNT = 5; private BitChartLegacy _chart = default!; private BitChartLegacyLineConfig _config = default!; protected override void OnInitialized() { _config = new BitChartLegacyLineConfig { Options = new BitChartLegacyLineOptions { Responsive = true, Title = new BitChartLegacyOptionsTitle { Display = true, Text = "BitChartLegacy Time Scale Chart" }, Tooltips = new BitChartLegacyTooltips { Mode = BitChartLegacyInteractionMode.Nearest, Intersect = true }, Hover = new BitChartLegacyHover { Mode = BitChartLegacyInteractionMode.Nearest, Intersect = true }, Scales = new BitChartLegacyScales { XAxes = [ new BitChartLegacyTimeAxis { ScaleLabel = new BitChartLegacyScaleLabel { LabelString = "Date" }, Time = new BitChartLegacyTimeOptions { TooltipFormat = "dd MMM HH:mm" }, GridLines = new BitChartLegacyGridLines { Color = "gray" } } ], YAxes = [ new BitChartLegacyLinearCartesianAxis { ScaleLabel = new BitChartLegacyScaleLabel { LabelString = "Value" }, GridLines = new BitChartLegacyGridLines { Color = "gray" } } ] } } }; _config.Data.Labels.AddRange(BitChartLegacyDemoUtils.GetNextDays(INITAL_COUNT).Select(d => d.ToString("o"))); IDataset dataset1 = new BitChartLegacyLineDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT)) { Label = "My first dataset", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Red), BorderColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Red), Fill = BitChartLegacyFillingMode.Disabled }; IDataset dataset2 = new BitChartLegacyLineDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT)) { Label = "My second dataset", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Blue), BorderColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Blue), Fill = BitChartLegacyFillingMode.Disabled }; IDataset dataset3 = new BitChartLegacyLineDataset() { Label = "Dataset with point data", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Green), BorderColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Green), Fill = BitChartLegacyFillingMode.Disabled }; DateTime now = DateTime.Now; dataset3.Add(new BitChartLegacyTimePoint(now, BitChartLegacyDemoUtils.RandomScalingFactor())); dataset3.Add(new BitChartLegacyTimePoint(now.AddDays(2), BitChartLegacyDemoUtils.RandomScalingFactor())); dataset3.Add(new BitChartLegacyTimePoint(now.AddDays(3), BitChartLegacyDemoUtils.RandomScalingFactor())); dataset3.Add(new BitChartLegacyTimePoint(now.AddDays(4), BitChartLegacyDemoUtils.RandomScalingFactor())); _config.Data.Datasets.Add(dataset1); _config.Data.Datasets.Add(dataset2); _config.Data.Datasets.Add(dataset3); } private void RandomizeData() { foreach (IBitChartLegacyDataset dataset in _config.Data.Datasets) { if (dataset is IDataset pointDataset) { for (int i = 0; i < pointDataset.Count; i++) { pointDataset[i] = new BitChartLegacyTimePoint(pointDataset[i].Time, BitChartLegacyDemoUtils.RandomScalingFactor()); } } else if (dataset is IDataset intDataset) { int count = intDataset.Count; intDataset.Clear(); foreach (var factor in BitChartLegacyDemoUtils.RandomScalingFactor(count)) { intDataset.Add(factor); } } } _chart.Update(); } private void AddDataset() { string color = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.All[_config.Data.Datasets.Count % BitChartLegacyDemoColors.All.Count]); IDataset dataset = new BitChartLegacyLineDataset(BitChartLegacyDemoUtils.RandomScalingFactor(_config.Data.Labels.Count)) { Label = $"Dataset {_config.Data.Datasets.Count}", BackgroundColor = color, BorderColor = color, Fill = BitChartLegacyFillingMode.Disabled }; _config.Data.Datasets.Add(dataset); _chart.Update(); } private void RemoveDataset() { IList datasets = _config.Data.Datasets; if (datasets.Count == 0) return; datasets.RemoveAt(datasets.Count - 1); _chart.Update(); } private void AddData() { if (_config.Data.Datasets.Count == 0) return; DateTime now = DateTime.Now; _config.Data.Labels.Add(now.AddDays(_config.Data.Labels.Count).ToString("o")); foreach (IBitChartLegacyDataset dataset in _config.Data.Datasets) { if (dataset is IDataset pointDataset) { pointDataset.Add(new BitChartLegacyTimePoint(now.AddDays(pointDataset.Count), BitChartLegacyDemoUtils.RandomScalingFactor())); } else if (dataset is IDataset intDataset) { intDataset.Add(BitChartLegacyDemoUtils.RandomScalingFactor()); } } _chart.Update(); } private void RemoveData() { if (_config.Data.Datasets.Count == 0) return; IList labels = _config.Data.Labels; if (labels.Count > 0) labels.RemoveAt(labels.Count - 1); foreach (IBitChartLegacyDataset dataset in _config.Data.Datasets) { if (dataset is IDataset pointDataset && pointDataset.Count > 0) { pointDataset.RemoveAt(pointDataset.Count - 1); } else if (dataset is IDataset intDataset && intDataset.Count > 0) { intDataset.RemoveAt(intDataset.Count - 1); } } _chart.Update(); } public static class BitChartLegacyDemoColors { private static readonly Lazy> _all = new(() => [ Red, Orange, Yellow, Green, Blue, Purple, Grey ]); public static IReadOnlyList All => _all.Value; public static readonly System.Drawing.Color Red = System.Drawing.Color.FromArgb(255, 99, 132); public static readonly System.Drawing.Color Orange = System.Drawing.Color.FromArgb(255, 159, 64); public static readonly System.Drawing.Color Yellow = System.Drawing.Color.FromArgb(255, 205, 86); public static readonly System.Drawing.Color Green = System.Drawing.Color.FromArgb(75, 192, 192); public static readonly System.Drawing.Color Blue = System.Drawing.Color.FromArgb(54, 162, 235); public static readonly System.Drawing.Color Purple = System.Drawing.Color.FromArgb(153, 102, 255); public static readonly System.Drawing.Color Grey = System.Drawing.Color.FromArgb(201, 203, 207); } public static class BitChartLegacyDemoUtils { public static readonly Random _rng = new(); public static IReadOnlyList Months { get; } = new ReadOnlyCollection( [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]); private static int RandomScalingFactorThreadUnsafe(int min, int max) => _rng.Next(min, max); public static int RandomScalingFactor() { lock (_rng) { return RandomScalingFactorThreadUnsafe(0, 100); } } public static IEnumerable RandomScalingFactor(int count, int min = 0, int max = 100) { int[] factors = new int[count]; lock (_rng) { for (int i = 0; i < count; i++) { factors[i] = RandomScalingFactorThreadUnsafe(min, max); } } return factors; } public static IEnumerable GetNextDays(int count) { DateTime now = DateTime.Now; DateTime[] factors = new DateTime[count]; for (int i = 0; i < factors.Length; i++) { factors[i] = now.AddDays(i); } return factors; } } public static class IListExtensions { public static void AddRange(this IList list, IEnumerable items) { if (list == null) throw new ArgumentNullException(nameof(list)); if (items == null) throw new ArgumentNullException(nameof(items)); if (list is List asList) { asList.AddRange(items); } else { foreach (T item in items) { list.Add(item); } } } } ``` \n**Scatter**: ```razor Randomize Data Add Dataset Remove Dataset ``` ```csharp private const int INITAL_COUNT = 5; private BitChartLegacy _chart = default!; private BitChartLegacyScatterConfig _config = default!; protected override void OnInitialized() { _config = new BitChartLegacyScatterConfig() { Options = new BitChartLegacyLineOptions { Scales = new BitChartLegacyScales { XAxes = [ new BitChartLegacyLinearCartesianAxis { ScaleLabel = new BitChartLegacyScaleLabel { LabelString = "Value" }, GridLines = new BitChartLegacyGridLines { Color = "gray" } } ], YAxes = [ new BitChartLegacyLinearCartesianAxis { ScaleLabel = new BitChartLegacyScaleLabel { LabelString = "Value" }, GridLines = new BitChartLegacyGridLines { Color = "gray" } } ] } } }; _config.Data.Labels.AddRange(BitChartLegacyDemoUtils.GetNextDays(INITAL_COUNT).Select(d => d.ToString("o"))); var dataset1 = new BitChartLegacyScatterDataset(BitChartLegacyDemoUtils.CreateRandomPoints(10)) { Label = "My first dataset", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Red), BorderColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Red), }; var dataset2 = new BitChartLegacyScatterDataset(BitChartLegacyDemoUtils.CreateRandomPoints(10)) { Label = "My second dataset", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Blue), BorderColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Blue), }; var dataset3 = new BitChartLegacyScatterDataset(BitChartLegacyDemoUtils.CreateRandomPoints(10)) { Label = "Dataset with point data", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Green), BorderColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Green), }; _config.Data.Datasets.Add(dataset1); _config.Data.Datasets.Add(dataset2); _config.Data.Datasets.Add(dataset3); } private void RandomizeData() { foreach (IBitChartLegacyDataset dataset in _config.Data.Datasets) { if (dataset is BitChartLegacyScatterDataset scatterDataset) { int count = scatterDataset.Count; scatterDataset.Clear(); scatterDataset.AddRange(BitChartLegacyDemoUtils.CreateRandomPoints(count)); } } _chart.Update(); } private void AddDataset() { string color = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.All[_config.Data.Datasets.Count % BitChartLegacyDemoColors.All.Count]); var newDataset = new BitChartLegacyScatterDataset(BitChartLegacyDemoUtils.CreateRandomPoints(_config.Data.Labels.Count)) { Label = $"Dataset {_config.Data.Datasets.Count + 1}", BackgroundColor = color, BorderColor = color, }; _config.Data.Datasets.Add(newDataset); _chart.Update(); } private void RemoveDataset() { IList datasets = _config.Data.Datasets; if (datasets.Count == 0) return; datasets.RemoveAt(datasets.Count - 1); _chart.Update(); } public static class BitChartLegacyDemoColors { private static readonly Lazy> _all = new(() => [ Red, Orange, Yellow, Green, Blue, Purple, Grey ]); public static IReadOnlyList All => _all.Value; public static readonly System.Drawing.Color Red = System.Drawing.Color.FromArgb(255, 99, 132); public static readonly System.Drawing.Color Orange = System.Drawing.Color.FromArgb(255, 159, 64); public static readonly System.Drawing.Color Yellow = System.Drawing.Color.FromArgb(255, 205, 86); public static readonly System.Drawing.Color Green = System.Drawing.Color.FromArgb(75, 192, 192); public static readonly System.Drawing.Color Blue = System.Drawing.Color.FromArgb(54, 162, 235); public static readonly System.Drawing.Color Purple = System.Drawing.Color.FromArgb(153, 102, 255); public static readonly System.Drawing.Color Grey = System.Drawing.Color.FromArgb(201, 203, 207); } public static class BitChartLegacyDemoUtils { public static readonly Random _rng = new(); public static IReadOnlyList Months { get; } = new ReadOnlyCollection( [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]); private static int RandomScalingFactorThreadUnsafe(int min, int max) => _rng.Next(min, max); public static int RandomScalingFactor() { lock (_rng) { return RandomScalingFactorThreadUnsafe(0, 100); } } public static IEnumerable RandomScalingFactor(int count, int min = 0, int max = 100) { int[] factors = new int[count]; lock (_rng) { for (int i = 0; i < count; i++) { factors[i] = RandomScalingFactorThreadUnsafe(min, max); } } return factors; } public static IEnumerable GetNextDays(int count) { DateTime now = DateTime.Now; DateTime[] factors = new DateTime[count]; for (int i = 0; i < factors.Length; i++) { factors[i] = now.AddDays(i); } return factors; } public static List CreateRandomPoints(int count) { List points = new(); for (int i = 0; i < count; i++) { double x = RandomScalingFactor(); double y = RandomScalingFactor(); points.Add(new BitChartLegacyPoint(x, y)); } return points; } } public static class IListExtensions { public static void AddRange(this IList list, IEnumerable items) { if (list == null) throw new ArgumentNullException(nameof(list)); if (items == null) throw new ArgumentNullException(nameof(items)); if (list is List asList) { asList.AddRange(items); } else { foreach (T item in items) { list.Add(item); } } } } ``` \n**Bubble**: ```razor Randomize Data Add Dataset Remove Dataset ``` ```csharp private const int INITAL_COUNT = 5; private BitChartLegacy _chart = default!; private BitChartLegacyBubbleConfig _config = default!; protected override void OnInitialized() { _config = new BitChartLegacyBubbleConfig { Options = new BitChartLegacyLineOptions { Responsive = true, Title = new BitChartLegacyOptionsTitle { Display = true, Text = "BitChartLegacy Bubble Chart" }, Tooltips = new BitChartLegacyTooltips { Mode = BitChartLegacyInteractionMode.Nearest, Intersect = true }, Hover = new BitChartLegacyHover { Mode = BitChartLegacyInteractionMode.Nearest, Intersect = true }, Scales = new BitChartLegacyScales { XAxes = [ new BitChartLegacyLinearCartesianAxis { ScaleLabel = new BitChartLegacyScaleLabel { LabelString = "Value" }, GridLines = new BitChartLegacyGridLines { Color = "gray" } } ], YAxes = [ new BitChartLegacyLinearCartesianAxis { ScaleLabel = new BitChartLegacyScaleLabel { LabelString = "Value" }, GridLines = new BitChartLegacyGridLines { Color = "gray" } } ] } } }; _config.Data.Labels.AddRange(BitChartLegacyDemoUtils.GetNextDays(INITAL_COUNT).Select(d => d.ToString("o"))); var dataset1 = new BitChartLegacyBubbleDataset(BitChartLegacyDemoUtils.CreateRandomBubblePoints(10)) { Label = "My first dataset", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Red), BorderColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Red), }; var dataset2 = new BitChartLegacyBubbleDataset(BitChartLegacyDemoUtils.CreateRandomBubblePoints(10)) { Label = "My second dataset", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Blue), BorderColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Blue), }; var dataset3 = new BitChartLegacyBubbleDataset(BitChartLegacyDemoUtils.CreateRandomBubblePoints(10)) { Label = "Dataset with point data", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Green), BorderColor = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.Green), }; _config.Data.Datasets.Add(dataset1); _config.Data.Datasets.Add(dataset2); _config.Data.Datasets.Add(dataset3); } private void RandomizeData() { foreach (IBitChartLegacyDataset dataset in _config.Data.Datasets) { if (dataset is BitChartLegacyBubbleDataset bubbleDataset) { int count = bubbleDataset.Count; bubbleDataset.Clear(); bubbleDataset.AddRange(BitChartLegacyDemoUtils.CreateRandomBubblePoints(count)); } } _chart.Update(); } private void AddDataset() { string color = BitChartLegacyColorUtil.FromDrawingColor(BitChartLegacyDemoColors.All[_config.Data.Datasets.Count % BitChartLegacyDemoColors.All.Count]); var newDataset = new BitChartLegacyBubbleDataset(BitChartLegacyDemoUtils.CreateRandomBubblePoints(_config.Data.Labels.Count)) { Label = $"Dataset {_config.Data.Datasets.Count + 1}", BackgroundColor = color, BorderColor = color, }; _config.Data.Datasets.Add(newDataset); _chart.Update(); } private void RemoveDataset() { IList datasets = _config.Data.Datasets; if (datasets.Count == 0) return; datasets.RemoveAt(datasets.Count - 1); _chart.Update(); } public static class BitChartLegacyDemoColors { private static readonly Lazy> _all = new(() => [ Red, Orange, Yellow, Green, Blue, Purple, Grey ]); public static IReadOnlyList All => _all.Value; public static readonly System.Drawing.Color Red = System.Drawing.Color.FromArgb(255, 99, 132); public static readonly System.Drawing.Color Orange = System.Drawing.Color.FromArgb(255, 159, 64); public static readonly System.Drawing.Color Yellow = System.Drawing.Color.FromArgb(255, 205, 86); public static readonly System.Drawing.Color Green = System.Drawing.Color.FromArgb(75, 192, 192); public static readonly System.Drawing.Color Blue = System.Drawing.Color.FromArgb(54, 162, 235); public static readonly System.Drawing.Color Purple = System.Drawing.Color.FromArgb(153, 102, 255); public static readonly System.Drawing.Color Grey = System.Drawing.Color.FromArgb(201, 203, 207); } public static class BitChartLegacyDemoUtils { public static readonly Random _rng = new(); public static IReadOnlyList Months { get; } = new ReadOnlyCollection( [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]); private static int RandomScalingFactorThreadUnsafe(int min, int max) => _rng.Next(min, max); public static int RandomScalingFactor() { lock (_rng) { return RandomScalingFactorThreadUnsafe(0, 100); } } public static IEnumerable RandomScalingFactor(int count, int min = 0, int max = 100) { int[] factors = new int[count]; lock (_rng) { for (int i = 0; i < count; i++) { factors[i] = RandomScalingFactorThreadUnsafe(min, max); } } return factors; } public static IEnumerable GetNextDays(int count) { DateTime now = DateTime.Now; DateTime[] factors = new DateTime[count]; for (int i = 0; i < factors.Length; i++) { factors[i] = now.AddDays(i); } return factors; } public static List CreateRandomBubblePoints(int count) { List points = new(); for (int i = 0; i < count; i++) { double x = RandomScalingFactor(); double y = RandomScalingFactor(); double radius = RandomScalingFactor() % 20 + 5; points.Add(new BitChartLegacyBubblePoint(x, y, radius)); } return points; } } public static class IListExtensions { public static void AddRange(this IList list, IEnumerable items) { if (list == null) throw new ArgumentNullException(nameof(list)); if (items == null) throw new ArgumentNullException(nameof(items)); if (list is List asList) { asList.AddRange(items); } else { foreach (T item in items) { list.Add(item); } } } } ``` \n**Radar Chart**: ```razor Randomize Data Add Dataset Remove Dataset Add Data Remove Data ``` ```csharp private const int INITAL_COUNT = 8; private BitChartLegacy _chart = default!; private BitChartLegacyRadarConfig _config = default!; protected override void OnInitialized() { _config = new BitChartLegacyRadarConfig { Options = new BitChartLegacyRadarOptions() { Responsive = true, Title = new BitChartLegacyOptionsTitle { Display = true, Text = "BitChartLegacy Radar Chart" }, Scale = new BitChartLegacyLinearRadialAxis { GridLines = new BitChartLegacyGridLines { Color = "gray" } } } }; IDataset dataset1 = new BitChartLegacyRadarDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT)) { Label = "Dataset 1", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(System.Drawing.Color.FromArgb(128, BitChartLegacyDemoColors.Red)) }; IDataset dataset2 = new BitChartLegacyRadarDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT)) { Label = "Dataset 2", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(System.Drawing.Color.FromArgb(128, BitChartLegacyDemoColors.Blue)) }; IDataset dataset3 = new BitChartLegacyRadarDataset(BitChartLegacyDemoUtils.RandomScalingFactor(INITAL_COUNT)) { Label = "Dataset 3", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(System.Drawing.Color.FromArgb(128, BitChartLegacyDemoColors.Orange)) }; _config.Data.Datasets.Add(dataset1); _config.Data.Datasets.Add(dataset2); _config.Data.Datasets.Add(dataset3); } private void RandomizeRadarData() { foreach (IDataset dataset in _config.Data.Datasets) { int count = dataset.Count; dataset.Clear(); for (int i = 0; i < count; i++) { if (BitChartLegacyDemoUtils._rng.NextDouble() < 0.2) { dataset.Add(0); } else { dataset.Add(BitChartLegacyDemoUtils.RandomScalingFactor()); } } } _chart.Update(); } private void AddRadarDataset() { System.Drawing.Color color = BitChartLegacyDemoColors.All[_config.Data.Datasets.Count % BitChartLegacyDemoColors.All.Count]; IDataset dataset = new BitChartLegacyRadarDataset(BitChartLegacyDemoUtils.RandomScalingFactor(_config.Data.Labels.Count)) { Label = $"Dataset {_config.Data.Datasets.Count + 1}", BackgroundColor = BitChartLegacyColorUtil.FromDrawingColor(System.Drawing.Color.FromArgb(128, color)), BorderColor = BitChartLegacyColorUtil.FromDrawingColor(color), BorderWidth = 1 }; _config.Data.Datasets.Add(dataset); _chart.Update(); } private void RemoveRadarDataset() { IList datasets = _config.Data.Datasets; if (datasets.Count == 0) return; datasets.RemoveAt(datasets.Count - 1); _chart.Update(); } private void AddRadarData() { if (_config.Data.Datasets.Count == 0) return; string month = BitChartLegacyDemoUtils.Months[_config.Data.Labels.Count % BitChartLegacyDemoUtils.Months.Count]; _config.Data.Labels.Add(month); foreach (IDataset dataset in _config.Data.Datasets) { dataset.Add(BitChartLegacyDemoUtils.RandomScalingFactor()); } _chart.Update(); } private void RemoveRadarData() { if (_config.Data.Datasets.Count == 0 || _config.Data.Labels.Count == 0) { return; } _config.Data.Labels.RemoveAt(_config.Data.Labels.Count - 1); foreach (IDataset dataset in _config.Data.Datasets) { dataset.RemoveAt(dataset.Count - 1); } _chart.Update(); } public static class BitChartLegacyDemoColors { private static readonly Lazy> _all = new(() => [ Red, Orange, Yellow, Green, Blue, Purple, Grey ]); public static IReadOnlyList All => _all.Value; public static readonly System.Drawing.Color Red = System.Drawing.Color.FromArgb(255, 99, 132); public static readonly System.Drawing.Color Orange = System.Drawing.Color.FromArgb(255, 159, 64); public static readonly System.Drawing.Color Yellow = System.Drawing.Color.FromArgb(255, 205, 86); public static readonly System.Drawing.Color Green = System.Drawing.Color.FromArgb(75, 192, 192); public static readonly System.Drawing.Color Blue = System.Drawing.Color.FromArgb(54, 162, 235); public static readonly System.Drawing.Color Purple = System.Drawing.Color.FromArgb(153, 102, 255); public static readonly System.Drawing.Color Grey = System.Drawing.Color.FromArgb(201, 203, 207); } public static class BitChartLegacyDemoUtils { public static readonly Random _rng = new(); public static IReadOnlyList Months { get; } = new ReadOnlyCollection( [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]); private static int RandomScalingFactorThreadUnsafe(int min, int max) => _rng.Next(min, max); public static int RandomScalingFactor() { lock (_rng) { return RandomScalingFactorThreadUnsafe(0, 100); } } public static IEnumerable RandomScalingFactor(int count, int min = 0, int max = 100) { int[] factors = new int[count]; lock (_rng) { for (int i = 0; i < count; i++) { factors[i] = RandomScalingFactorThreadUnsafe(min, max); } } return factors; } public static IEnumerable GetNextDays(int count) { DateTime now = DateTime.Now; DateTime[] factors = new DateTime[count]; for (int i = 0; i < factors.Length; i++) { factors[i] = now.AddDays(i); } return factors; } } public static class IListExtensions { public static void AddRange(this IList list, IEnumerable items) { if (list == null) throw new ArgumentNullException(nameof(list)); if (items == null) throw new ArgumentNullException(nameof(items)); if (list is List asList) { asList.AddRange(items); } else { foreach (T item in items) { list.Add(item); } } } } ```