Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LiveChartsCore.SkiaSharpView.Blazor: zh-CN content becomes squares #793

Closed
LeaFrock opened this issue Dec 1, 2022 · 6 comments
Closed
Labels
blazor bug Something isn't working priority 0 needs to be fixed asap.

Comments

@LeaFrock
Copy link

LeaFrock commented Dec 1, 2022

Describe the bug

First of all, I've seen the previous issues #140 #347 #636 . The solutions of them do not work for me (which make me 😕 & 😞 ).

I have a hosted blazor wasm project (ASP.NET Core 6) which uses livechart2 and runs on CentOS.

The first version of LiveChartsCore.SkiaSharpView.Blazor I used is 2.0.0-beta.513.

Bug 1: About Legends

The chart looks like the image below,

1669876422788

When the lib version is <= 2.0.0-beta.516, the Chinese chars are shown well in the legends. But after 2.0.0-beta.600, they become squares.

Bug 2: About Axis Name Paint

This bug exists for all versions since beta.513. When I'm trying to use Chinese as the axis name,

        public Axis[] XAxes { get; set; } = new Axis[]
        {
            new Axis
            {
                Name = "日期",
                Labels = Array.Empty<string>(),
                LabelsRotation = 60,
                NamePaint = new SolidColorPaint()
                {
                    Color= SKColors.Black,
                    SKTypeface = SKFontManager.Default.MatchCharacter('汉')// Solution 1
                    // SKTypeface = SKTypeface.FromFamilyName("Microsoft YaHei UI"),// Solution 2
                    // FontFamily = "Microsoft YaHei UI" // Solution 3
                }
            }
        };

All the three solutions do not work and the browser console shows System.DllNotFoundException: libHarfBuzzSharp exceptions like below,

1669877807495

To Reproduce

All related code of the project are limited to the basic usage of CartesianChart.

The only difference is that I want to take Chinese characters as the legend and axis name.

Expected behavior

Show zh-CN characters correctly.

Desktop (please complete the following information):

  • OS: [Win10 22H2]
  • Browser [Edge 107.0.1418.62]
  • Version [2.0.0-beta.603]
@zylalx1
Copy link

zylalx1 commented Dec 1, 2022

Same problem (Bug 1) and solved.
The method of setting FontFamily has changed. In previous versions you set LegendFontFamily and TooltipFontFamily, but these properties have been removed in beta.600.

Try this:
MyChart.LegendTextPaint = new SolidColorPaint { Color = SKColors.Black, FontFamily = "Microsoft YaHei UI" }; MyChart.TooltipTextPaint = new SolidColorPaint { Color = SKColors.Black, FontFamily = "Microsoft YaHei UI" };

BTW, "\n" works well as linebreaks in tooltips in previous versions, but for some mysterious reason it became a square in beta.603. I solved this by replacing it with "\r\n".

@LeaFrock
Copy link
Author

LeaFrock commented Dec 2, 2022

@zylalx1 Thanks for your comment. If so, that's a break change because the legend used to work well even though you don't clarify LegendTextPaint at all before beta.600.

<CartesianChart 
                        Series="ChartViewModel.Series"
                        XAxes="ChartViewModel.XAxes"
                        YAxes="ChartViewModel.YAxes"
                        LegendPosition="LiveChartsCore.Measure.LegendPosition.Right" />

Also, once I take your suggestion, the bug 2 appears again. It seems the native .dll does not support browser, at least I don't find it in the published runtime/browser file (but do find in runtime/win-x64).

1669945958979

1669945686384

@beto-rodriguez
Copy link
Owner

Yes, the API changed to what @zylalx1 mentioned, the docs will be updated soon.

I also get the error message in the WASM sample even when trying your suggestion @zylalx1, need to investigate this further.

You can see the error here: https://blazor-livecharts.controli.app/Axes/LabelsFormat2

@MithrilMan
Copy link
Contributor

FYI I fixed the issue of missing DLL (on my Blazor WASM project) by dong this:

I've added an explicit reference to
<PackageReference Include="HarfBuzzSharp.NativeAssets.WebAssembly" Version="2.8.2.3" />

I've added an explicit NativeFileReference

<ItemGroup>
      <NativeFileReference Include="$(HarfBuzzSharpStaticLibraryPath)\2.0.23\*.a" />
   </ItemGroup>

info source: mono/SkiaSharp#1725 (comment)

@beto-rodriguez
Copy link
Owner

beto-rodriguez commented Jan 5, 2023

Yes @MithrilMan that seems to fix the issue, I was able to make this work with #848. I will explain that in the docs in the next version of the library.

This is how to setup things in the next version of the library, HarfBuzz must be explicitly included (SkiaSharp/HarfBuzz bug?)

<ItemGroup>
    <NativeFileReference Include="$(HarfBuzzSharpStaticLibraryPath)\2.0.23\*.a" />
 </ItemGroup>

@beto-rodriguez beto-rodriguez added the priority 0 needs to be fixed asap. label Mar 3, 2023
@beto-rodriguez
Copy link
Owner

This is fixed now, please check the Blazor sample in this repo, it works properly there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blazor bug Something isn't working priority 0 needs to be fixed asap.
Projects
None yet
Development

No branches or pull requests

4 participants