private void DrawSamples(RadarChartSample[] samples, string axis, double lineLength, double currentAngle) { var axisSamples = samples.Where(s => s.AxisShortName == axis); foreach (var sample in axisSamples) { var valueLength = sample.Value * sample.Scale * lineLength / MaxValue; var dx = valueLength * Math.Sin(currentAngle); var dy = valueLength * Math.Cos(currentAngle); SampleToAngleDictionary.Add(sample, currentAngle); DrawSample(sample, CanvasWidth / 2 + dx, CanvasHeight / 2 + dy, currentAngle); } }
public void RedrawChart(RadarChartSample[] samples) { SampleToAngleDictionary.Clear(); ClearCanvas(); if (samples == null || !samples.Any()) { return; } var axes = samples.Select(s => s.AxisShortName).ToArray(); var currentAngle = 0d; var angleChange = (2 * Math.PI) / axes.Length; var lineLength = CanvasHeight < CanvasWidth ? CanvasHeight / 2 : CanvasWidth / 2; CalculatedMaxLineLength = lineLength; List <Tuple <double, double> > previousTicks = null; List <Tuple <double, double> > firstTicks = null; foreach (var axis in axes) { DrawAxis(axis, lineLength, currentAngle); var ticks = CalculateTicks(axis, currentAngle, lineLength, axes.Length < 3); if (axes.Length > 2) { if (firstTicks == null) { firstTicks = new List <Tuple <double, double> >(ticks); } if (previousTicks != null) { DrawWebLines(previousTicks, ticks); } previousTicks = ticks; } DrawSamples(samples, axis, lineLength, currentAngle); currentAngle += angleChange; } if (axes.Length > 2) { DrawWebLines(firstTicks, previousTicks); } DrawValueRangePolygon(samples, lineLength, MaxValue); DrawValueCompartmentsPolygons(lineLength); }