-
Notifications
You must be signed in to change notification settings - Fork 6
Known-issues #18
Comments
Hi ! Concerning the serialization issue for client-side projects, any chance you add [JsonObject(MemberSerialization.OptIn)] attribute to serializable classes as a workaround ? |
Hey. I'm sorry but I believe that isn't really possible. That would require me to manually add this attribute to 20-50 classes. This is already quite a bunch of attributes but you have to keep in mind that I would also have to add the If you're using it currently your best bet is waiting until the migration from I'm really sorry about this bug but I believe there isn't really something I can do currently. If you find another workaround that doesn't require that much work and doesn't pollute the project as much, by all means, tell me :) |
Adding @using ChartJs.Blazor.Charts
@using ChartJs.Blazor.ChartJS.PieChart
@using ChartJs.Blazor.ChartJS.Common.Properties
@using System.ComponentModel
<ChartJsPieChart @ref="pieChartJs" Config="@config" Width="300" Height="300" />
@code {
private PieChartConfig config;
private ChartJsPieChart pieChartJs;
private ReferenceConverter ReferenceConverter = new ReferenceConverter(typeof(ChartJsPieChart));
protected override void OnInit()
{
config = new PieChartConfig
{
CanvasId = "myFirstPieChart",
Options = new PieChartOptions
{
Title = new OptionsTitle
{
Display = true,
Text = "Sample chart from Blazor"
},
Responsive = true,
Animation = new DoughnutAnimation
{
AnimateRotate = true,
AnimateScale = true
}
}
};
config.Data.Labels = new List<string> { "A", "B", "C", "D" };
var pieSet = new PieChartDataset
{
BackgroundColor = new[] { "#ff6384", "#55ee84", "#4463ff", "#efefef" },
Data = new List<int> { 4, 5, 6, 7 }, // this will be removed and shouldn't be possible
Label = "Light Red",
BorderWidth = 0,
HoverBackgroundColor = new[] { "#f06384" },
HoverBorderColor = new[] { "#f06384" },
HoverBorderWidth = new[] { 1 },
BorderColor = "#ffffff",
};
config.Data.Datasets = new List<PieChartDataset>(); // this will be removed and shouldn't be possible
config.Data.Datasets.Add(pieSet);
}
} seems to resolve the problem (shows a valid object in the Browser debugging console), but does not draw the chart. |
@Joelius300 , make sens I understand. I'll add the attribute to charts I wanted to draw on my side and wait for the fix. @SeppPenner , same result here, no more error but no chart neither. |
Interestingly, this workaround works perfectly fine for me. I will post the two pages I tested below. I'm using a standard client-side blazor application created and used with preview7. I did not do anything special to this project so I would suggest you to upgrade your SDK to the newest preview and update all your dependencies in the current project. Hopefully this will help you fix this issue. LineChart
PieChart (code from comment above)
|
Strange... I have all my dependencies up-to-date already... |
It worked with Joelius' code and... with mine without changing anything. Looks like a cache issue or something. But hey working charts yay ! |
Mhm, I will try to check this again today. For me, it didn't work yesterday. |
@Joelius300 It worked for me as well. I had a stupid issue: I put the code you posted into a new Blazor component called private ReferenceConverter converter = new ReferenceConverter(typeof(DoughnutChart)); instead of: private ReferenceConverter converter = new ReferenceConverter(typeof(ChartJsPieChart)); |
I have put this information to the wiki: https://github.com/Joelius300/ChartJSBlazor/wiki/Known-issues. For me, it makes more sense to document this kind of stuff there because it can be found more easily. (The issues are getting long after a while). |
Good idea. I'll close this issue now as it isn't needed anymore. |
Static assets from the library can't be consumed in a server-side blazor application
Even though the static assets in the library are correctly placed, they can only be consumed by client-side projects currently. We hope that this changes in the future previews.
If you're using server-side blazor or there is some issue with the static-asset-consumption, you should manually download the files from here, put them in the
wwwroot
folder of your project and directly reference them (forget_content
in that case).MissingMethodException when using client-side blazor
Currently there seems to be a serialization issue for client-side projects. It's related to this bug from json.net.
Sadly there isn't really much we can do about this since we currently rely on json.net.Thanks @SeppPenner for presenting a workaround that actually works. See this comment for how to do it and some more after that if you want details.
This bug will be entirely fixed either in an update of json.net, (blazor) or when the migration from
Newtonsoft.Json
toSystem.Text.Json
is complete.The text was updated successfully, but these errors were encountered: