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 starts in the "wrong" location until "right" location is moused over #773

Closed
begleysm opened this issue Nov 24, 2022 · 4 comments
Closed
Labels
avalonia more info required not verified It is probably an issue, but we have not enough evidence to mark this as a bug.

Comments

@begleysm
Copy link

Describe the bug
I am using LiveCharts2 in Avalonia. I have two charts setup inside a Grid. When I open the window the charts are displayed "offset" up and to the left. Once I mouse-over the correct location they "pop" into position.

Expected behavior
I would expect the charts to show up in their designated grid spot upon the window opening.

Screenshots
Here is a GIF showing what I mean.
must-mouse-over

Desktop (please complete the following information):

  • OS: Windows 10
  • Framework: Avalonia
  • Version: Avalonia 0.10.18, LiveCharts2 2.0.0-beta.330

Code
VIEW

<Grid RowDefinitions="60,160,60,60,100,100" ColumnDefinitions="*,*,*,*">
						
	.
	.
	.

	<Grid RowDefinitions="40,*" ColumnDefinitions="*,*" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4">
		<TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Bottom">Control Network Status</TextBlock>
		<Border Grid.Row="1" Grid.Column="0" BorderBrush="Green" BorderThickness="2" CornerRadius="3">
			<lvc:CartesianChart EasingFunction="{x:Null}" Series="{Binding NetworkTrafficSeries}"></lvc:CartesianChart>
		</Border>
		<TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Top" FontSize="10" FontStyle="Italic" Margin="5,5,0,0">Dropped Packets:    In = 10    Out = 2</TextBlock>
		
		<TextBlock Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Bottom">Data Network Status</TextBlock>
		<Border Grid.Row="1" Grid.Column="1" BorderBrush="Red" BorderThickness="2" CornerRadius="3">
			<lvc:CartesianChart EasingFunction="{x:Null}" Series="{Binding NoOutputTrafficSeries}"></lvc:CartesianChart>
		</Border>
		<TextBlock Grid.Row="1" Grid.Column="1" VerticalAlignment="Top" FontSize="10" FontStyle="Italic" Margin="5,5,0,0">Dropped Packets:    In = 5    Out = 1234</TextBlock>
	</Grid>
	
	.
	.
	.
	
</Grid>

VIEWMODEL

.
.
.
public class VPXModuleWindowViewModel : ViewModelBase
    {
        private static double[] DataIn = new double[100];
        private static double[] DataIn2 = new double[100];
        private static double[] DataOut = new double[100];
        private static double[] DataZero = new double[100];

        public VPXModuleWindowViewModel()
        {
            Random rnd = new Random();
            for (int i = 0; i < DataIn.Length; i++)
            {
                DataIn[i] = rnd.Next(100);
                DataIn2[i] = rnd.Next(100);
                DataOut[i] = rnd.Next(100);
                if (i < 20)
                {
                    DataZero[i] = rnd.Next(100);
                }
                else
                {
                    DataZero[i] = 0;
                }
            }
        }
        
        public ISeries[] NetworkTrafficSeries { get; set; } =
        {
            new LineSeries<double>
            {
                Name = "In",
                Values = DataIn, 
                Fill = null,
                GeometrySize = 0,
                LineSmoothness = 0,
                Stroke = new SolidColorPaint(SKColors.YellowGreen) { StrokeThickness = 1 }
            },

            new LineSeries<double>
            {
                Name = "Out",
                Values = DataOut,
                Fill = null,
                GeometrySize = 0,
                LineSmoothness = 0,
                Stroke = new SolidColorPaint(SKColors.DodgerBlue) { StrokeThickness = 1 }
            }
        };
        
        public ISeries[] NoOutputTrafficSeries { get; set; } =
        {
            new LineSeries<double>
            {
                Name = "In",
                Values = DataIn2, 
                Fill = null,
                GeometrySize = 0,
                LineSmoothness = 0,
                Stroke = new SolidColorPaint(SKColors.YellowGreen) { StrokeThickness = 1 }
            },

            new LineSeries<double>
            {
                Name = "Out",
                Values = DataZero,
                Fill = null,
                GeometrySize = 0,
                LineSmoothness = 0,
                Stroke = new SolidColorPaint(SKColors.DodgerBlue) { StrokeThickness = 1 }
            }
        };
    }

.
.
.
@beto-rodriguez
Copy link
Owner

beto-rodriguez commented Dec 18, 2022

Hello and thanks for the issue.

This is strange, I am not completely sure if this is an issue of Live Charts, notice in this repository all the charts start or their actual position, could you please provide a small repository or test project with the issue?

@beto-rodriguez beto-rodriguez added avalonia not verified It is probably an issue, but we have not enough evidence to mark this as a bug. more info required labels Dec 18, 2022
@begleysm
Copy link
Author

begleysm commented Jan 6, 2023

I probably can't create a minimal example at this time. I changed the way my GUI works and it doesn't happen anymore, but it was long ago enough that I'm not quite sure how to quickly get back there. You can probably close this.

@GF-Huang
Copy link

GF-Huang commented Feb 13, 2023

I have similar problem. After add data into series, the chart not show correct until I click/zooming it.

BQuOoEYFLZ

...
<lvc:CartesianChart Visibility="{Binding IsLoadingData, Converter={StaticResource Boolean2VisibilityReConverter}}" 
                    Series="{Binding Series}" XAxes="{Binding XAxes}" ZoomMode="X" />
...
public class ViewModel {
    public IReadOnlyList<Axis> XAxes { get; } = new[] {
        new Axis {
            Labeler = value => value >= 0 ? new DateTime((long)value).ToString("HH:mm") : string.Empty,
            UnitWidth = TimeSpan.FromMinutes(1).Ticks
        }
    };

    public IReadOnlyList<ISeries> Series { get; }

    public ObservableCollection<FinancialPoint> DataPoints { get; } = new();

    public StockViewModel() {
        Series = new[] {
            new CandlesticksSeries<FinancialPoint> {
                Values = DataPoints,
                TooltipLabelFormatter = 
                    p => $"{p.Model?.Date:HH:mm} O: {p.Model?.Open} H: {p.Model?.High} L: {p.Model?.Low} C: {p.Model?.Close}",
            }
        };
    }    

    public async Task LoadData() {
        try {
            IsLoadingData = true;

            var data = await LoadSomethingData();

            foreach (var s in data) {
                DataPoints.Add(new FinancialPoint(
                    s.Time,
                    (double)s.High,
                    (double)s.Open,
                    (double)s.Close,
                    (double)s.Low
                ));
            }

        } finally {
            IsLoadingData = false;
        }
    }
}
.NET 7 
LiveCharts WPF 2.0.0-beta.701
Win11 22H2 x64

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

This is hard to reproduce, in general there will be multiple improvements in the library in the next version (beta-800), I will close this for now since we can not reproduce it and it is probably already fixed, I fixed a bunch of render issues and added multiple tests, probably this got fixed some there in #1028 or #1021 please open a new issue if the error persists after beta 800 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
avalonia more info required not verified It is probably an issue, but we have not enough evidence to mark this as a bug.
Projects
None yet
Development

No branches or pull requests

3 participants