beto-rodriguez / LiveCharts2

Simple, flexible, interactive & powerful charts, maps and gauges for .Net, LiveCharts2 can now practically run everywhere Maui, Uno Platform, Blazor-wasm, WPF, WinForms, Xamarin, Avalonia, WinUI, UWP.
https://livecharts.dev
MIT License
4.38k stars 572 forks source link

How do I make it work? #1561

Closed Bodden007 closed 3 months ago

Bodden007 commented 3 months ago

I did everything as written https://livecharts.dev/docs/WPF/2.0.0-rc2/samples.lines.basic `using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;

namespace WpfSample { ///

/// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } } } <Window x:Class="WpfSample.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:WpfSample" xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF">

<lvc:CartesianChart
    Series="{Binding Series}">
</lvc:CartesianChart>

<UserControl x:Class="WpfSample.UserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:WpfSample" xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF" xmlns:vms="clr-namespace:WpfSample;assembly=WpfSample">

<UserControl.DataContext>
    <vms:ViewModel/>
</UserControl.DataContext>
<lvc:CartesianChart Series="{Binding Series}" Title="{Binding Title}" MinWidth="500" MinHeight="500" />

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace WpfSample { public partial class View:UserControl { public View() { InitializeComponent(); } } } using LiveChartsCore.SkiaSharpView; using LiveChartsCore; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using LiveChartsCore.SkiaSharpView.Painting; using SkiaSharp; using LiveChartsCore.SkiaSharpView.VisualElements;

namespace WpfSample { public class ViewModel : ObservableObject { public ISeries[] Series { get; set; } = { new LineSeries { Values = new double[] { 2, 1, 3, 5, 3, 4, 6 }, Fill = null } };

    public LabelVisual Title { get; set; } =
        new LabelVisual
        {
            Text = "My chart title",
            TextSize = 25,
            Padding = new LiveChartsCore.Drawing.Padding(15),
            Paint = new SolidColorPaint(SKColors.DarkSlateGray)
        };
}

} ` 2024-08-07_195818

What is missing, why is it not working? Why is there no normal explanation?

beto-rodriguez commented 3 months ago

I don't speak Russian, but it seems that your XAML is not able to find the ViewModel, ensure your namespace is correct, I will close this for now.

I will move this to a discussion since this is not an issue with the library, maybe you can find help there!