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

Visual Element not working (gauge not visible) #1794

Open
Mietrits opened this issue Feb 5, 2025 · 3 comments
Open

Visual Element not working (gauge not visible) #1794

Mietrits opened this issue Feb 5, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@Mietrits
Copy link

Mietrits commented Feb 5, 2025

So i'm trying to show the angluar gauge in my .net maui app. But it is not really working out.

I figured this has something to do with the VisualElement from the beginnen because when i paste the ViewModel code into my project it instantly gives this error:

'VisualElement' is an ambiguous reference between 'Microsoft.Maui.Controls.VisualElement' and 'LiveChartsCore.VisualElements.VisualElement'

This error can be fixed by changing this line:
public IEnumerable<VisualElement> VisualElements { get; set; }

To this:
public IEnumerable<LiveChartsCore.VisualElements.VisualElement> VisualElements { get; set; }

But the gauge isn't visible when i debug.

When i remove the line VisualElements="{Binding VisualElements}" in the MainPage.xaml The blue, red and green zones are shown.

Someone any ideas?

@Mietrits Mietrits changed the title Visual Element bug Visual Element not working Feb 5, 2025
@Mietrits Mietrits changed the title Visual Element not working Visual Element not working (gauge not visible) Feb 5, 2025
@Doodeletion
Copy link

I don't think the ambiguous reference error is related to your gauge not showing.
Did you check for binding errors?

'VisualElement' is an ambiguous reference between 'Microsoft.Maui.Controls.VisualElement' and 'LiveChartsCore.VisualElements.VisualElement' just means that you imported 2 classes with the name VisualElement.
If you check your using statements at the top of your file you should see both usings unless Maui auto-imports things for you (I've never worked with it).

using LiveChartsCore.SkiaSharpView.VisualElements;
using Microsoft.Maui.Controls.VisualElement;

If you need Maui's VisualElement class in this file, resolving the LiveCharts error by using the fully qualified name LiveChartsCore.VisualElements.VisualElement is perfectly fine. If you don't need Maui's VIsualElement in this file, remove its using statement.

@Mietrits
Copy link
Author

Mietrits commented Feb 6, 2025

Yes i already tried that, so this line:
public IEnumerable<LiveChartsCore.VisualElements.VisualElement> VisualElements { get; set; }
solves the error but as i said the gauge is not visible yet unless i remove this line:
VisualElements="{Binding VisualElements}"

See the picture for an example.
Image

On top of that im not using micosoft.maui.controls.visualelement these are my usings:

using System.Collections.Generic;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Extensions;
using LiveChartsCore.VisualElements;
using LiveChartsCore.SkiaSharpView.VisualElements;
using LiveChartsCore.Defaults;
using CommunityToolkit.Mvvm.Input;
using System;

Visual studio tells me that these are unnecessary:

using System.Collections.Generic;
using LiveChartsCore.VisualElements;
using System;

@beto-rodriguez
Copy link
Owner

HI and thanks for the issue.

I understand the confusion, some LiveCharts objects share the same name as Maui objects, I will keep this in mind to improve this in future versions.

As a general rule, use LiveCharts objects if you are building a chart, this library does not use Maui to draw, everything is drawn by SkiaSharp.

@beto-rodriguez beto-rodriguez added the enhancement New feature or request label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants