You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Still have not been able to auto update (adding a single point to the exist series) the cartesianChart without it loading the whole series all over when I update it.
My ViewModel code has a public static List candleList object that stores the points and I use external class to call a public method inside the ViewModel class to update the candleList list however when it calls the method the cartesianchart reloads the whole completely instead of just adding the last datetime point to the end. Not sure if this is a limitation of candlestick charts only as it seems to work for other observablepoint types? (Eg; Is there a way to implement the INotifyCollectionChanged for other types aside from ObservablePoint or a way to implement this?)
//ViewModel class:
public class ViewModel : INotifyPropertyChanged
{
public static List<FinancialPoint> candleList = new List<FinancialPoint>();
public ObservableCollection<ISeries> Series { get; set; } = new ObservableCollection<ISeries>
{
new CandlesticksSeries<FinancialPoint>
{
Values = candleList
}
};
//Method to add last FinancialPoint from the list fP to the end of the candleList which is linked to the values of the Series
public void addSeriesAuto(List<FinancialPoint> fP)
{
if (candleList.Count == 0)
{
candleList = fP;
System.Windows.Forms.MessageBox.Show("candlelist is empty!");
}
else if (candleList[candleList.Count-1].Date.ToString() == fP[fP.Count-1].Date.ToString())
{
candleList[fP.Count - 1] = fP[fP.Count - 1];
System.Windows.Forms.MessageBox.Show("candlelist contains fp: "+ fP[fP.Count-1].Date.ToString());
}
else
{
candleList.Add(fP[fP.Count - 1]);
System.Windows.Forms.MessageBox.Show("Added value to candlelist fp: " + fP[fP.Count - 1].Date.ToString());
}
}
}
Calling the above method from external class:
viewM.addSeriesAuto(fPList); //should add the last FinancialPoint to the cartesian chart but instead it reloads the whole series.
The sample code for Winforms->Lines/Autoupdate seems to work with a LineSeries Observable collection so maybe it is a limitation of FinancialPoint or am I doing something wrong?, sample code here:
using LiveChartsCore;
using LiveChartsCore.Defaults;
using LiveChartsCore.SkiaSharpView;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Input;
namespace ViewModelsSamples.Lines.AutoUpdate
{
public class ViewModel
{
private int _index = 0;
private readonly Random _random = new Random();
private readonly ObservableCollection<ObservablePoint> _observableValues;
public ViewModel()
{
// using an INotifyCollectionChanged instance as your values collection
// will let the chart update every time a point is added, removed, replaced or the whole list was cleared
_observableValues = new ObservableCollection<ObservablePoint>
{
// using an object that implements INotifyPropertyChanged
// will allow the chart to update everytime a property in a point changes.
// LiveCharts already provides the ObservableValue class
// notice you can plot any type, but you must let LiveCharts know how to handle it
// for more info please see:
// https://github.com/beto-rodriguez/LiveCharts2/blob/master/samples/ViewModelsSamples/General/UserDefinedTypes/ViewModel.cs#L22
new ObservablePoint(_index++, 2),
new ObservablePoint(_index++, 5),
new ObservablePoint(_index++, 4),
new ObservablePoint(_index++, 5),
new ObservablePoint(_index++, 2),
new ObservablePoint(_index++, 6),
new ObservablePoint(_index++, 6),
new ObservablePoint(_index++, 6),
new ObservablePoint(_index++, 4),
new ObservablePoint(_index++, 2),
new ObservablePoint(_index++, 3),
new ObservablePoint(_index++, 4),
new ObservablePoint(_index++, 3)
};
// using a collection that implements INotifyCollectionChanged as your series collection
// will allow the chart to update every time a series is added, removed, replaced or the whole list was cleared
// .Net already provides the System.Collections.ObjectModel.ObservableCollection class
Series = new ObservableCollection<ISeries>
{
new LineSeries<ObservablePoint>
{
Values = _observableValues,
Fill = null
}
};
// in the following series notice that the type int does not implement INotifyPropertyChanged
// and our Series.Values collection is of type List<T>
// List<T> does not implement INotifyCollectionChanged
// this means the following series is not listening for changes.
//Series.Add(new LineSeries<int> { Values = new List<int> { 2, 4, 6, 1, 7, -2 } });
}
public ObservableCollection<ISeries> Series { get; set; }
public void AddItem()
{
var randomValue = _random.Next(1, 10);
_observableValues.Add(
new ObservablePoint { X = _index++, Y = randomValue });
}
public void RemoveFirstItem()
{
if (_observableValues.Count == 0) return;
_observableValues.RemoveAt(0);
}
public void UpdateLastItem()
{
var randomValue = _random.Next(1, 10);
_observableValues[_observableValues.Count - 1].Y = randomValue;
}
public void ReplaceRandomItem()
{
var randomValue = _random.Next(1, 10);
var randomIndex = _random.Next(0, _observableValues.Count - 1);
_observableValues[randomIndex] =
new ObservablePoint { X = _observableValues[randomIndex].X, Y = randomValue };
}
public void AddSeries()
{
// for this sample only 5 series are supported.
if (Series.Count == 5) return;
Series.Add(
new LineSeries<int>
{
Values = new List<int> { _random.Next(0, 10), _random.Next(0, 10), _random.Next(0, 10) }
});
}
public void RemoveLastSeries()
{
if (Series.Count == 1) return;
Series.RemoveAt(Series.Count - 1);
}
// The next commands are only to enable XAML bindings
// they are not used in the WinForms sample
public ICommand AddItemCommand => new Command(o => AddItem());
public ICommand RemoveItemCommand => new Command(o => RemoveFirstItem());
public ICommand UpdateItemCommand => new Command(o => UpdateLastItem());
public ICommand ReplaceItemCommand => new Command(o => ReplaceRandomItem());
public ICommand AddSeriesCommand => new Command(o => AddSeries());
public ICommand RemoveSeriesCommand => new Command(o => RemoveLastSeries());
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Still have not been able to auto update (adding a single point to the exist series) the cartesianChart without it loading the whole series all over when I update it.
My ViewModel code has a public static List candleList object that stores the points and I use external class to call a public method inside the ViewModel class to update the candleList list however when it calls the method the cartesianchart reloads the whole completely instead of just adding the last datetime point to the end. Not sure if this is a limitation of candlestick charts only as it seems to work for other observablepoint types? (Eg; Is there a way to implement the INotifyCollectionChanged for other types aside from ObservablePoint or a way to implement this?)
Calling the above method from external class:
viewM.addSeriesAuto(fPList); //should add the last FinancialPoint to the cartesian chart but instead it reloads the whole series.
The sample code for Winforms->Lines/Autoupdate seems to work with a LineSeries Observable collection so maybe it is a limitation of FinancialPoint or am I doing something wrong?, sample code here:
Beta Was this translation helpful? Give feedback.
All reactions