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
Xamarin app is crashing when we scroll on multi line chart on the ListView in iOS version.
We are facing the issue when we have multiple multiline charts in ListView .
The same code is working in all Android versions.
It is not working in iPhone 12 and above.
The iOS version is 13.6.
Please refer the below screen shot.
We are following below code snippet.
{
public IEnumerable<IEnumerable> MultiLineEntires { get; set; }
public List LegendNames { get; set; }
private bool initiated = false;
private float multiLineMax;
private float multiLineMin;
private List points = new List();
private void Init()
{
if (initiated)
{
return;
}
initiated = true;
foreach (List<ChartEntry> line in MultiLineEntires)
{
foreach (ChartEntry entry in line)
{
if (entry.Value > multiLineMax)
{
multiLineMax = entry.Value;
}
if (entry.Value < multiLineMin)
{
multiLineMin = entry.Value;
}
}
}
}
public override void DrawContent(SKCanvas canvas, int width, int height)
{
Init();
//height -= 60;
Entries = MultiLineEntires.ElementAt(0);
var valueLableSizes = MeasureLabels(MultiLineEntires.ElementAt(0).Select(x => x.Label).ToArray());
//var valueLableSizes = new SKRect[0];
var footerHeight = CalculateFooterHeaderHeight(valueLableSizes, Orientation.Horizontal);
var itemSize = CalculateItemSize(width, height, footerHeight, 100);
var origin = CalculateYOrigin(itemSize.Height, 100);
foreach (IEnumerable<ChartEntry> l in MultiLineEntires)
{
Entries = l;
var tempPoints = CalculateMultiLinePoints(itemSize, origin, 100);
points.AddRange(tempPoints);
//points = new List<SKPoint>();
DrawLine(canvas, tempPoints, itemSize);
DrawPoints(canvas, tempPoints);
//if(MultiLineEntires.IndexOf(l) == 0)
//{
//DrawArea(canvas, tempPoints, itemSize, origin);
DrawFooter(canvas, l.Select(x => x.Label).ToArray(), valueLableSizes, tempPoints, itemSize, height, footerHeight);
//}
}
DrawLegends(canvas, width, height);
}
private void DrawLegends(SKCanvas canvas, int width, int height)
{
if (!LegendNames.Any()) { return; }
List<SKColor> colors = new List<SKColor> { };
int incrementalCount = 0;
foreach (List<ChartEntry> l in MultiLineEntires)
{
if (!l.Any())
{
if (incrementalCount == 0)
colors.Add(SKColors.OrangeRed);
if(incrementalCount == 1)
colors.Add(SKColor.Parse("#f86c6b"));
}
else
{ colors.Add(l[0].Color); }
incrementalCount++;
}
int radius_size = 20;
using (var paint = new SKPaint())
{
paint.TextSize = this.LabelTextSize;
paint.IsAntialias = true;
paint.IsStroke = false;
float x = 200 + radius_size * 2;
float y = 50;
foreach (string legend in LegendNames)
{
paint.Color = SKColor.Parse("#000000");
canvas.DrawText(legend, x + radius_size + 10, y, paint);
paint.Color = colors.ElementAt(LegendNames.IndexOf(legend));
canvas.DrawCircle(x, y - radius_size / 2 - radius_size / 4, radius_size, paint);
x += radius_size * 2 + this.LabelTextSize * (legend.Length / 2 + 2);
}
float minPoint = 0;
float maxPoint = 0;
if(points != null && points.Any())
{
minPoint = points.Min(p => p.Y);
maxPoint = points.Max(p => p.Y);
}
paint.Color = SKColor.Parse("#000000");
paint.TextSize = 20;
//canvas.DrawCircle(12, minPoint, 5, paint);
canvas.DrawText(NumbersTools.GetNember(multiLineMax), 0, minPoint - 20, paint);
//canvas.DrawCircle(12, maxPoint, 5, paint);
canvas.DrawText(NumbersTools.GetNember(multiLineMin), 0, maxPoint - 20, paint);
float step = maxPoint / 8;
float valueStep = multiLineMax / 6;
int iterationValue = 6;
if(multiLineMax > 0 && multiLineMin < 0)
{
canvas.DrawText("0", 0, (maxPoint - step) - 20, paint);
}
for (int i = 1; i < iterationValue; i++)
{
var tt = (maxPoint - step * (i + 1));
if (minPoint < tt && Math.Abs(minPoint - tt) >= step)
{
var numberString = NumbersTools.GetNember(valueStep * i);
//canvas.DrawCircle(12, (maxPoint - step * i), 5, paint);
canvas.DrawText(numberString, 0, tt - 20, paint);
}
}
}
}
private SKPoint[] CalculateMultiLinePoints(SKSize itemSize, float origin, int headerHeight)
{
var result = new List<SKPoint>();
var entryList = this.Entries.ToList();
var zeroEntry = entryList.Find(x => x.Value == 0);
var isZeroCreated = false;
if (zeroEntry != null)
{
isZeroCreated = true;
}
if(zeroEntry == null && multiLineMin < 0 && multiLineMax > 0)
{
entryList.Add(new ChartEntry(0)
{
Color = SKColor.Parse("#33CCCC"),
TextColor = SKColors.Black,
ValueLabel = string.Empty,
Label = string.Empty
});
}
for (int i = 0; i < entryList.Count(); i++)
{
var entry = entryList.ElementAt(i);
if(entry.Value <= 0 && !isZeroCreated)
{
isZeroCreated = true;
continue;
}
var x = this.Margin + (itemSize.Width / 2) + (i * (itemSize.Width + this.Margin));
var y = headerHeight + (((multiLineMax - entry.Value) / (multiLineMax - multiLineMin)) * itemSize.Height);
var point = new SKPoint(x, y);
result.Add(point);
}
return result.ToArray();
}
}
The text was updated successfully, but these errors were encountered:
Xamarin app is crashing when we scroll on multi line chart on the ListView in iOS version.
We are facing the issue when we have multiple multiline charts in ListView .
The same code is working in all Android versions.
It is not working in iPhone 12 and above.
The iOS version is 13.6.
Please refer the below screen shot.
We are following below code snippet.
{
public IEnumerable<IEnumerable> MultiLineEntires { get; set; }
public List LegendNames { get; set; }
private bool initiated = false;
private float multiLineMax;
private float multiLineMin;
private List points = new List();
The text was updated successfully, but these errors were encountered: