[Question] Does anyone know why my chart on ASP.Net Core only renders data on first load?
See original GitHub issueI’ve been trying to use Microcharts inside an ASP.Net Core 3.1 application and have encountered the following problems:
- The chart renders with data on the first refresh, but on subsequent refreshes it only shows the entry labels (no values or chart lines). If I restart the ASP.Net application, I can get the data to appear again.
- On that first refresh, the sizing of the Y axis is off and chart lines appear very low on chart.
I’m using .Net Core 3.1 and Microcharts 0.9.5.1. The code for my action method is below and I’m assuming I’m missing something super basic and silly, but just can’t spot it! 😅
public IActionResult ChartTest()
{
var entries = new[]
{
new ChartEntry(212)
{
Label = "UWP",
ValueLabel = "212",
Color = SKColor.Parse("#2c3e50"),
TextColor = SKColor.Parse("#000000")
},
new ChartEntry(248)
{
Label = "Android",
ValueLabel = "248",
Color = SKColor.Parse("#77d065"),
TextColor = SKColor.Parse("#000000")
},
new ChartEntry(128)
{
Label = "iOS",
ValueLabel = "128",
Color = SKColor.Parse("#b455b6"),
TextColor = SKColor.Parse("#000000")
},
new ChartEntry(514)
{
Label = "Forms",
ValueLabel = "514",
Color = SKColor.Parse("#3498db"),
TextColor = SKColor.Parse("#000000")
}
};
var chart = new LineChart
{
Entries = entries,
LabelOrientation = Orientation.Horizontal,
LineMode = LineMode.Spline,
MaxValue = 1000,
MinValue = 0
};
var width = 800;
var height = 500;
var bitmap = new SKBitmap(width, height);
bitmap.Erase(SKColor.Parse("#ffffff"));
var canvas = new SKCanvas(bitmap);
chart.DrawContent(canvas, width, height);
using (var image = SKImage.FromPixels(bitmap.PeekPixels()))
{
using (var data = image.Encode(SKEncodedImageFormat.Jpeg, 100))
{
var memStream = new MemoryStream();
data.SaveTo(memStream);
memStream.Seek(0, SeekOrigin.Begin);
return new FileStreamResult(memStream, "image/jpeg");
}
}
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
charts loading problem - asp.net mvc
If you're using .NET 4, the charting controls are now built-in. There's some info on Scott Guthrie's blog:.
Read more >Memory management and patterns in ASP.NET Core
The following graph is generated with a relatively small load in to show how memory allocations are impacted by the GC. Graph showing...
Read more >Displaying Data in a Chart with ASP.NET Web Pages (Razor)
This article explains how to use a chart to display data in an ASP.NET Web Pages (Razor) website by using the Chart helper....
Read more >How to create dynamic Charts in ASP.NET MVC - YouTube
In this video we demonstrate very simplify on how to implement charts dynamically using Chartjs. We have also shown how to make ajax...
Read more >ASP.NET MVC Tutorial - Data Binding and Hierarchical ...
This guide will present an example of using ASP.NET MVC model binding to present and collect hierarchical form data in a hierarchical structure....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Might I suggest to change the text in the README to better reflect this aspect? By reading it, it looks like Microcharts is a general purpose chart library, and this is misleading.
I can alter the readme, the target audience is honestly really xamarin and desktop apps.