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

Chart not rendering properly in WPF .net6.0 #1008

Closed
yurui105 opened this issue May 11, 2023 · 4 comments
Closed

Chart not rendering properly in WPF .net6.0 #1008

yurui105 opened this issue May 11, 2023 · 4 comments

Comments

@yurui105
Copy link

Describe the bug
Using the code in the example, the chart will not be generated after running the program, and the chart will be generated normally after manually dragging the window, but the zoom is not normal, and the maximum and minimum cannot be displayed normally.

To Reproduce
Steps to reproduce the behavior:

  1. Ues Visual Studio 2022 create a WPF project.
  2. Install dependencies packages
  3. Copy example PieChart code.
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
using CommunityToolkit.Mvvm.ComponentModel;
using System.Collections.Generic;
using LiveChartsCore.SkiaSharpView.Painting;
using SkiaSharp;
using LiveChartsCore.SkiaSharpView.VisualElements;

namespace ViewModel;

public partial class ViewModel : ObservableObject
{
    public ViewModel()
    {
        // you could convert any IEnumerable to a pie series collection
        var data = new double[] { 2, 4, 1, 4, 3 };

        // Series = data.AsLiveChartsPieSeries(); this could be enough in some cases 
        // but you can customize the series properties using the following overload: 

        Series = data.AsLiveChartsPieSeries((value, series) =>
        {
            // here you can configure the series assigned to each value.
            series.Name = $"Series for value {value}";
            series.DataLabelsPaint = new SolidColorPaint(new SKColor(30, 30, 30));
            series.DataLabelsPosition = LiveChartsCore.Measure.PolarLabelsPosition.Outer;
            series.DataLabelsFormatter = p => $"{p.PrimaryValue} / {p.StackedValue!.Total} ({p.StackedValue.Share:P2})";
        });

        // this is an equivalent and more verbose syntax. 
        // Series = new ISeries[]
        // {
        //     new PieSeries<double> { Values = new double[] { 2 }, Name = "Slice 1" },
        //     new PieSeries<double> { Values = new double[] { 4 }, Name = "Slice 2" },
        //     new PieSeries<double> { Values = new double[] { 1 }, Name = "Slice 3" },
        //     new PieSeries<double> { Values = new double[] { 4 }, Name = "Slice 4" },
        //     new PieSeries<double> { Values = new double[] { 3 }, Name = "Slice 5" }
        // };
    }

    public IEnumerable<ISeries> Series { get; set; }

    public LabelVisual Title { get; set; } =
        new LabelVisual
        {
            Text = "My chart title",
            TextSize = 25,
            Padding = new LiveChartsCore.Drawing.Padding(15),
            Paint = new SolidColorPaint(SKColors.DarkSlateGray)
        };
}
  1. Add PieChart component in xaml file
<Window x:Class="WpfApp1.MainWindow"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
       xmlns:local="clr-namespace:WpfApp1"
       xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF"
       xmlns:vms="clr-namespace:ViewModel"
       mc:Ignorable="d"
       Title="MainWindow" Height="450" Width="800">
   <Window.DataContext>
       <vms:ViewModel></vms:ViewModel>
   </Window.DataContext>
   <Grid>
       <lvc:PieChart
           Series="{Binding Series}"
           Title="{Binding Title}"
           LegendPosition="Right"></lvc:PieChart>
   </Grid>
</Window>

Expected behavior
charts display normal.

Screenshots
Unable to display normally when starting the program
image
The graph is displayed after moving the window, but it is incomplete
image
Maximized cannot be fully filled
image

Desktop (please complete the following information):

  • OS: Windows10
  • WPF
  • Browser: chrome
  • Version 2.0.0-beta.710

Additional context
Add any other context about the problem here.

@denizmaral
Copy link

Well, I followed your steps and it worked on my computer.

@beto-rodriguez
Copy link
Owner

beto-rodriguez commented May 16, 2023

Same for me, I think there is something missing to reproduce this issue.

@yurui105
Copy link
Author

@beto-rodriguez @denizmaral
This seems to be a known issue.
I fixed it by #509 (comment)

@beto-rodriguez
Copy link
Owner

Nice, glad to read that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants