I am building an SfChart with a LineSeries, which gets data from an ObservableCollection<model> ItemSource, in which the model has a DateTime and a double for X & Y. The chart draws nicely and updates when a new element is added to the ObservableCollection from elsewhere.
However, I have tried to add a Trendline, which either does not draw, or draws only a horizontal line, depending on what Type I choose.
I create the Trendline as follows:
Trendline trendline = new Trendline()
{
Label = "trend",
IsTrendlineVisible = true,
Stroke = new SolidColorBrush(Colors.Red),
StrokeThickness = 2,
Type = TrendlineType.Linear
};
Then I attach the Trendline to the LineSeries and attach the LineSeries to the SfChart:
LSeries.Trendlines.Add(trendline);
chart.Series.Add(LSeries);
Perhaps the Trendline isn't being made aware of the new data? Is there some way to fix this?
Many thanks for your reply.
I am having a similar problem with trying to instantiate a CandleSeries on an SfChart and then update the data in real time, to add new candles to the series. The chart and series are generated in C#, not in XAML.
If there is no data when the chart and series are created, then new data added to the series is not shown. But if there is data provided when the chart and series are created, then new data can be added dynamically -- it can be seen.
That problem has an obvious workaround (create 'dummy' data at creation, and then remove it when new data exists). But will the new release also fix this problem -- are they related?
Many thanks again.