using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls; // for registering Ignite UI modulesnamespaceInfragistics.Samples
{
publicclassProgram
{
publicstaticasync Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Ignite UI modules
builder.Services.AddIgniteUIBlazor(
typeof(IgbDataChartCoreModule),
typeof(IgbDataChartCategoryModule),
typeof(IgbDataChartFinancialModule),
typeof(IgbDataChartInteractivityModule)
);
await builder.Build().RunAsync();
}
}
}cs
using System;
using System.Collections.Generic;
namespaceInfragistics.Samples
{
publicclassSampleFinancialData
{
publicstatic Random random = new Random();
publicstatic List<SampleFinancialItem> Create(int itemsCount = 365)
{
var data = new List<SampleFinancialItem>();
// initial valuesvar v = 10000.0;
var o = 500.0;
var h = Math.Round(o + (random.NextDouble() * 5));
var l = Math.Round(o - (random.NextDouble() * 5));
var c = Math.Round(l + (random.NextDouble() * (h - l)));
var today = DateTime.Now;
var end = new DateTime(today.Year, 12, 31);
var time = end.AddDays(-itemsCount);
for (var i = 0; i < itemsCount; i++)
{
var date = time.ToShortDateString();
var label = GetShortDate(time, false);
// adding new data itemvar item = new SampleFinancialItem();
item.Time = time;
item.Date = date;
item.Label = label;
item.Close = c;
item.Open = o;
item.High = h;
item.Low = l;
item.Volume = v;
data.Add(item);
// generating new valuesvar mod = random.NextDouble() - 0.49;
o = Math.Round(o + (mod * 5 * 4));
v = Math.Round(v + (mod * 5 * 100));
h = Math.Round(o + (random.NextDouble() * 15));
l = Math.Round(o - (random.NextDouble() * 15));
c = Math.Round(l + (random.NextDouble() * (h - l)));
time = time.AddDays(1);
}
return data;
}
publicstaticstringGetShortDate(DateTime dt, bool showYear)
{
var months = new List<string> {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
var ind = dt.Month - 1;
var day = dt.Day;
var label = months[ind] + " " + day;
if (showYear)
{
label += " " + dt.Year;
}
return label;
}
}
publicclassSampleFinancialItem
{
publicdouble High { get; set; }
publicdouble Low { get; set; }
publicdouble Open { get; set; }
publicdouble Close { get; set; }
publicdouble Volume { get; set; }
publicstring Label { get; set; }
publicstring Date { get; set; }
public DateTime Time { get; set; }
}
}cs
//begin async datausing System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using System.Net.Http;
using System.Collections.ObjectModel;
using IgniteUI.Blazor.Controls;
publicclassMultipleStocks : List<TitledStockData>
{
publicasyncstatic Task<MultipleStocks> Fetch()
{
var google = await MultipleStocks.GetGoogleStock();
var amazon = await MultipleStocks.GetAmazonStock();
var val = new MultipleStocks();
val.Add(google);
val.Add(amazon);
return val;
}
/** gets Amazon stock OHLC prices from a .JSON file */publicasyncstatic Task<TitledStockData> GetAmazonStock()
{
var url = "https://static.infragistics.com/xplatform/data/stocks/stockAmazon.json";
var data = await Fetch(url);
var stockData = ConvertData(data);
stockData[0].Title = "Amazon";
return stockData;
}
/** gets Tesla stock OHLC prices from a .JSON file */publicasyncstatic Task<TitledStockData> GetTeslaStock()
{
var url = "https://static.infragistics.com/xplatform/data/stocks/stockTesla.json";
var data = await Fetch(url);
var stockData = ConvertData(data);
stockData[0].Title = "Tesla";
return stockData;
}
/** gets Microsoft stock OHLC prices from a .JSON file */publicasyncstatic Task<TitledStockData> GetMicrosoftStock()
{
var url = "https://static.infragistics.com/xplatform/data/stocks/stockMicrosoft.json";
var data = await Fetch(url);
var stockData = ConvertData(data);
stockData[0].Title = "Microsoft";
return stockData;
}
/** gets Google stock OHLC prices from a .JSON file */publicasyncstatic Task<TitledStockData> GetGoogleStock()
{
var url = "https://static.infragistics.com/xplatform/data/stocks/stockGoogle.json";
var data = await Fetch(url);
var stockData = ConvertData(data);
stockData[0].Title = "Google";
return stockData;
}
privateasyncstatic Task<Dictionary<string, object>[]> Fetch(string url)
{
HttpClient client = new HttpClient();
var str = await client.GetStringAsync(url);
var arr = JsonSerializer.Deserialize<Dictionary<string, object>[]>(str);
return arr;
}
publicstatic TitledStockData ConvertData(Dictionary<string, object>[] arr)
{
var ret = new TitledStockData();
foreach (var json in arr)
{
var date = ((JsonElement)json["date"]).GetString();
var parts = date.Split('-'); // "2020-01-01"var item = new MultipleStocksItem();
item.Date = new DateTime(int.Parse(parts[0]), int.Parse(parts[1]) + 1, int.Parse(parts[2]),12,0,0);
item.Open = ((JsonElement)json["open"]).GetDouble();
item.High = ((JsonElement)json["high"]).GetDouble();
item.Low = ((JsonElement)json["low"]).GetDouble();
item.Close = ((JsonElement)json["close"]).GetDouble();
item.Volume = ((JsonElement)json["volume"]).GetDouble();
ret.Add(item);
}
return ret;
}
}
publicclassMultipleStocksItem
{
[DataSeriesMemberIntent(DataSeriesIntent.SeriesTitle)]
publicstring Title { get; set; }
public DateTime Date { get; set; }
publicdouble Open { get; set; }
publicdouble High { get; set; }
publicdouble Low { get; set; }
publicdouble Close { get; set; }
publicdouble Volume { get; set; }
}
publicclassTitledStockData
: ObservableCollection<MultipleStocksItem>
{
}
//end async datacs
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using IgniteUI.Blazor.Controls; // for registering Ignite UI modulesnamespaceInfragistics.Samples
{
publicclassProgram
{
publicstaticasync Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Ignite UI modules
builder.Services.AddIgniteUIBlazor(
typeof(IgbFinancialChartModule),
typeof(IgbDataChartInteractivityModule),
typeof(IgbLegendModule)
);
await builder.Build().RunAsync();
}
}
}cs