-
Hello. I'm modifying some code on an older program to use Livecharts v2. When plotting a CandlesticksSeries just like in the example here https://livecharts.dev/docs/WPF/2.0.0-rc2/samples.financial.basicCandlesticks and when reducing the size of the window, candles do not get their width adjusted properly. Candles remain quite large and quickly overlap. This is as if a minimum width for each candle was set and this number was quite large (10px or so). This behavior does not happen with the ColumnSeries. In small window, columns automatically reduce their width much more. I have a CartesianChart that shows 2 series on the top of each other. One series is the CandlesticksSeries representing stock price (OLHC), the other series is a ColumnSeries representing traded volumes. The behavior in each case can be easily noticed. With Livecharts v0 I did not have this issue. Does anybody know what could be the problem? Is there a quick fix or is there a bug? Thank you all for this great piece of software. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Beta Was this translation helpful? Give feedback.
-
Thank you so much for your reply!!!! It's really nice of you. I will try your solution as soon as I have the time. I'm sure it's gonna work. Thank you for sharing your hard work! |
Beta Was this translation helpful? Give feedback.
-
I digged a little deeper in LiveCharts source code and came to the conclusion that the above hack proposed by TomDeFord should also work with WPF. After some debugging I found the culprit. The default strocke thickness used for candlestisck is quite large. And it is not taken into account for the calculation of the width of each candle. This means that the strocke of each candle covers the margin created by the hack above. So make sure that you set the strocke thickness to a minimum (1 for instance). var candleSeries = new CandlesticksSeries<FinancialPointI, CandlestickGeometryHack, LabelGeometry>
{
Values = _candlesticksSeriesValues,
UpFill = new SolidColorPaint(SKColors.Green),
UpStroke = new SolidColorPaint(SKColors.Green) { StrokeThickness = 1 },
DownFill = new SolidColorPaint(SKColors.Red),
DownStroke = new SolidColorPaint(SKColors.Red) { StrokeThickness = 1 }
}; A big thank you to TomDeFord for this hack. |
Beta Was this translation helpful? Give feedback.
I came across the same issue. The ColumnSeries inherits from BarSeries which has a padding property; unfortunately the CandleSticks don't have one. The code below is the smallest I could make my solution. If you want to add a property to the series class to nicely define the margin amount (on a per instance basis) it requires overriding of several LiveCharts classes.
I prefer the margin as a percentage of the width but the fixed width margin is there too.
Enjoy.