public async Task getSurfaceChartJson(string jsonResponse) { /// get the chart as a POCO #if tracing Console.WriteLine("1. Surface getChartJson"); Console.WriteLine("getChartJson(string jsonResponse)"); /// to capture the chart object's json from js #endif Surface3dManager.Initialize(jsonResponse); chart3Djson = JsonSerializer.Serialize <Surface.StackedColumns3DSurface>(Surface3dManager.chart); Surface3dManager.InitializePrices(localStorage, id); #if tracing Console.WriteLine("2. Surface getChartJson"); Console.WriteLine(chart3Djson); #endif await Task.Yield(); }
private async Task ChartSetData(Dictionary <string, BookDataItem[]> bookDataItems) { //await jsruntime.GroupTableAsync(bookDataItems, "bookDataItems"); try { #if tracing await jsruntime.InvokeVoidAsync("Dump", bookDataItems.Dumps(), "bookDataItems"); await jsruntime.InvokeVoidAsync("Dump", Surface3dManager.chart.Dumps(), "chart"); Console.WriteLine("4. Surface ChartSetData"); #endif //Surface3dManager.chart.title.text = "Surface"; //Surface3dManager.chart.plotOptions.column.depth = 1; Surface3dManager.PreSetProperties(); #if tracing Console.WriteLine("5. Surface ChartSetData"); #endif Surface3dManager.MaintainPriceAxis(bookDataItems, localStorage, id); /// Get the price range min and max over all items in the dictionary #if tracing Console.WriteLine("6. Surface ChartSetData"); #endif Chart_AdjustYaxis(bookDataItems); var categories = Surface3dManager.lstPrices.ToArray(); //Surface3dManager.lstPrices.Where(it => Convert.ToDouble(it) > minX - 0.05 && Convert.ToDouble(it) < maxX + 0.05).ToArray(); //Surface3dManager.chart.xAxis.max = categories.Count(); Surface3dManager.chart.xAxis.categories = categories; //Surface3dManager.chart.title.text = SurfaceChartConfigurator.showTitle; Surface3dManager.chart.title.text = TDAChart.LongDateString; //TDAChart.svcDateTime.ToLongDateString() + " " + TDAChart.svcDateTime.ToLongTimeString(); #if tracing await jsruntime.GroupTableAsync(Surface3dManager.chart.xAxis.categories, "Surface3dManager.chart.xAxis.categories"); await jsruntime.GroupTableAsync(Surface3dManager.chart.subtitle.text, "Surface3dManager.chart.subtitle.text"); ; /// Console.WriteLine("7. Surface ChartSetData"); #endif Chart_AddCandlePlotBands(bookDataItems, TDAChart.lastCandle, categories); //Chart_AddSpreadPlotBand(bookDataItems, categories); Chart_AddBollingerPlotLines(bookDataItems, categories); /// Convert BookDataItem[] to Series1[] Chart_BuildSeriesData(bookDataItems, categories, seriesList); /// TODO: /// 2. Control which items in series get passed to chart /// TODO: /// 3. Better just send new series to chart and let chart roll off stale data, it has series in memory. /// TODO: /// 4. Should only have to redraw if resize event, all else should just update specific chart property /// TODO: /// 5. Just direct jsRuntime calls for each property /// TODO: /// 6. Use jsRuntime extension methods so can name the calls and strong type parameters Surface3dManager.chart.series = seriesList.Take(46).ToArray(); #if tracing await jsruntime.GroupTableAsync(chart, "chart"); #endif //Surface3dManager.chart.Surface3dManager.chart.options3d.depth = Math.Max(100, Surface3dManager.chart.series.Count() * Surface3dManager.chart.plotOptions.column.depth); /// Send the new data and settings to the HighChart3D component /// Update the clock (current time only at this point) _clockDateTime = TDAChart.svcDateTime; var wholeChartJson = JsonSerializer.Serialize <Surface.StackedColumns3DSurface>(Surface3dManager.chart); chart3Djson = wholeChartJson; //if (seriesList.Count < 10) // chart3Djson = wholeChartJson; //else //{ // /// Instead, send just the data // var lstArray = JsonSerializer.Serialize<Surface.Series1[]>(lstNewSeries.ToArray()); // jsruntime.GroupTable(lstArray, "lstArray"); // chartSeriesJson = lstArray; //} #if tracing Console.WriteLine("8. Surface ChartSetData chart3Djson"); //Console.WriteLine(chart3Djson); #endif /// /// We should only send the series and the categories, not the whole chart /// But minor amouunt of config data involved in redraw /// Shuld only send series i case of a rolling series, /// instead of sending the whole matrix of data, just send the new row. /// chartSeriesJson = System.Text.Json.JsonSerializer.Serialize<Series1[]>(Surface3dManager.chart.series); //var chart3DseriesJson = JsonSerializer.Serialize<Series1[]>(Surface3dManager.chart.series); ; //var chart3DxAxisJson = JsonSerializer.Serialize<Xaxis>(Surface3dManager.chart.xAxis); StateHasChanged(); //await jsruntime.InvokeVoidAsync("setChart3Dseries", new object[] { chart3DseriesJson, chart3DxAxisJson }); await Task.CompletedTask; } catch { } }