protected override void OnParametersSet() { Circles.Clear(); Legends.Clear(); double counterClockwiseOffset = 25; double totalPercent = 0; double offset = counterClockwiseOffset; int counter = 0; foreach (double data in GetNormalizedData()) { double percent = data * 100; double reversePercent = 100 - percent; offset = 100 - totalPercent + counterClockwiseOffset; totalPercent = totalPercent + percent; var circle = new SvgCircle() { Index = counter, CX = 20, CY = 20, Radius = 15.91549430918954, StrokeDashArray = $"{ToS(percent)} {ToS(reversePercent)}", StrokeDashOffset = offset }; Circles.Add(circle); string labels = ""; if (counter < InputLabels.Length) { labels = InputLabels[counter]; } SvgLegend Legend = new SvgLegend() { Index = counter, Labels = labels, Data = data.ToString() }; Legends.Add(Legend); counter += 1; } }
protected override void OnParametersSet() { _paths.Clear(); _legends.Clear(); double startx, starty, endx, endy; var ndata = GetNormalizedData(); double cumulativeRadians = 0; for (var i = 0; i < ndata.Length; i++) { var data = ndata[i]; startx = Math.Cos(cumulativeRadians); starty = Math.Sin(cumulativeRadians); cumulativeRadians += 2 * Math.PI * data; endx = Math.Cos(cumulativeRadians); endy = Math.Sin(cumulativeRadians); var largeArcFlag = data > 0.5 ? 1 : 0; var path = new SvgPath() { Index = i, Data = $"M {ToS(startx)} {ToS(starty)} A 1 1 0 {ToS(largeArcFlag)} 1 {ToS(endx)} {ToS(endy)} L 0 0" }; _paths.Add(path); } var counter = 0; foreach (var data in ndata) { var percent = data * 100; var labels = ""; if (counter < InputLabels.Length) { labels = InputLabels[counter]; } var legend = new SvgLegend() { Index = counter, Labels = labels, Data = ToS(Math.Round(percent, 1)) }; _legends.Add(legend); counter += 1; } }
protected override void OnParametersSet() { base.OnParametersSet(); _horizontalLines.Clear(); _verticalLines.Clear(); _horizontalValues.Clear(); _verticalValues.Clear(); _legends.Clear(); _chartLines.Clear(); if (MudChartParent != null) { _series = MudChartParent.ChartSeries; } var maxY = 0.0; var numValues = 0; var numXLabels = XAxisLabels.Length; foreach (var item in _series) { if (numValues < item.Data.Length) { numValues = item.Data.Length; } foreach (int i in item.Data) { if (maxY < i) { maxY = i; } } } var boundHeight = 350.0; var boundWidth = 650.0; double gridYUnits = MudChartParent?.ChartOptions.YAxisTicks ?? 20; double gridXUnits = 30; var numVerticalLines = numValues - 1; var numHorizontalLines = ((int)(maxY / gridYUnits)) + 1; var verticalStartSpace = 25.0; var horizontalStartSpace = 30.0; var verticalEndSpace = 25.0; var horizontalEndSpace = 30.0; var verticalSpace = (boundHeight - verticalStartSpace - verticalEndSpace) / (numHorizontalLines); var horizontalSpace = (boundWidth - horizontalStartSpace - horizontalEndSpace) / (numVerticalLines); var interpolationOption = MudChartParent?.ChartOptions.InterpolationOption ?? InterpolationOption.Straight; //Horizontal Grid Lines var y = verticalStartSpace; double startGridY = 0; for (var counter = 0; counter <= numHorizontalLines; counter++) { var line = new SvgPath() { Index = counter, Data = $"M {ToS(horizontalStartSpace)} {ToS((boundHeight - y))} L {ToS((boundWidth - horizontalEndSpace))} {ToS((boundHeight - y))}" }; _horizontalLines.Add(line); var lineValue = new SvgText() { X = (horizontalStartSpace - 10), Y = (boundHeight - y + 5), Value = ToS(startGridY, MudChartParent?.ChartOptions.YAxisFormat) }; _horizontalValues.Add(lineValue); startGridY += gridYUnits; y += verticalSpace; } //Vertical Grid Lines var x = horizontalStartSpace; double startGridX = 0; for (var counter = 0; counter <= numVerticalLines; counter++) { var line = new SvgPath() { Index = counter, Data = $"M {ToS(x)} {ToS((boundHeight - verticalStartSpace))} L {ToS(x)} {ToS(verticalEndSpace)}" }; _verticalLines.Add(line); var xLabels = ""; if (counter < numXLabels) { xLabels = XAxisLabels[counter]; } var lineValue = new SvgText() { X = x, Y = boundHeight - 2, Value = xLabels }; _verticalValues.Add(lineValue); startGridX += gridXUnits; x += horizontalSpace; } //Chart Lines var colorcounter = 0; foreach (var item in _series) { var chartLine = ""; double gridValueX = 0; double gridValueY = 0; var firstTime = true; double[] XValues = new double[item.Data.Length]; double[] YValues = new double[item.Data.Length]; ILineInterpolator interpolator; for (var i = 0; i <= item.Data.Length - 1; i++) { if (i == 0) { XValues[i] = 30; } else { XValues[i] = XValues[i - 1] + horizontalSpace; } var gridValue = (item.Data[i]) * verticalSpace / gridYUnits; YValues[i] = boundHeight - (verticalStartSpace + gridValue); } switch (interpolationOption) { case InterpolationOption.NaturalSpline: interpolator = new NaturalSpline(XValues, YValues); break; case InterpolationOption.EndSlope: interpolator = new EndSlopeSpline(XValues, YValues); break; case InterpolationOption.Periodic: interpolator = new PeriodicSpline(XValues, YValues); break; case InterpolationOption.Straight: default: interpolator = new NoInterpolation(); break; } if (interpolator?.InterpolationRequired == true) { horizontalSpace = (boundWidth - horizontalStartSpace - horizontalEndSpace) / interpolator.InterpolatedXs.Length; foreach (var yValue in interpolator.InterpolatedYs) { if (firstTime) { chartLine += "M "; firstTime = false; gridValueX = horizontalStartSpace; gridValueY = verticalStartSpace; } else { chartLine += " L "; gridValueX += horizontalSpace; gridValueY = verticalStartSpace; } gridValueY = yValue; chartLine = chartLine + ToS(gridValueX) + " " + ToS(gridValueY); } } else { foreach (var dataLine in item.Data) { if (firstTime) { chartLine += "M "; firstTime = false; gridValueX = horizontalStartSpace; gridValueY = verticalStartSpace; } else { chartLine += " L "; gridValueX += horizontalSpace; gridValueY = verticalStartSpace; } var gridValue = ((double)dataLine) * verticalSpace / gridYUnits; gridValueY = boundHeight - (gridValueY + gridValue); chartLine = chartLine + ToS(gridValueX) + " " + ToS(gridValueY); } } var line = new SvgPath() { Index = colorcounter, Data = chartLine }; var legend = new SvgLegend() { Index = colorcounter, Labels = item.Name }; colorcounter++; _chartLines.Add(line); _legends.Add(legend); } }
protected override void OnParametersSet() { base.OnParametersSet(); _horizontalLines.Clear(); _verticalLines.Clear(); _horizontalValues.Clear(); _verticalValues.Clear(); _legends.Clear(); _bars.Clear(); if (MudChartParent != null) { _series = MudChartParent.ChartSeries; } var maxY = 0.0; var numValues = 0; var numXLabels = XAxisLabels.Length; foreach (var item in _series) { if (numValues < item.Data.Length) { numValues = item.Data.Length; } foreach (int i in item.Data) { if (maxY < i) { maxY = i; } } } var boundHeight = 350.0; var boundWidth = 650.0; double gridYUnits = MudChartParent?.ChartOptions.YAxisTicks ?? 20; double gridXUnits = 30; var numVerticalLines = numValues - 1; var numHorizontalLines = ((int)(maxY / gridYUnits)) + 1; var verticalStartSpace = 25.0; var horizontalStartSpace = 30.0; var verticalEndSpace = 25.0; var horizontalEndSpace = 30.0; var verticalSpace = (boundHeight - verticalStartSpace - verticalEndSpace) / (numHorizontalLines); var horizontalSpace = (boundWidth - horizontalStartSpace - horizontalEndSpace) / (numVerticalLines); //Horizontal Grid Lines var y = verticalStartSpace; double startGridY = 0; for (var counter = 0; counter <= numHorizontalLines; counter++) { var line = new SvgPath() { Index = counter, Data = $"M {ToS(horizontalStartSpace)} {ToS((boundHeight - y))} L {ToS((boundWidth - horizontalEndSpace))} {ToS((boundHeight - y))}" }; _horizontalLines.Add(line); var lineValue = new SvgText() { X = (horizontalStartSpace - 10), Y = (boundHeight - y + 5), Value = ToS(startGridY) }; _horizontalValues.Add(lineValue); startGridY += gridYUnits; y += verticalSpace; } //Vertical Grid Lines var x = horizontalStartSpace; double startGridX = 0; for (var counter = 0; counter <= numVerticalLines; counter++) { var line = new SvgPath() { Index = counter, Data = $"M {ToS(x)} {ToS((boundHeight - verticalStartSpace))} L {ToS(x)} {ToS(verticalEndSpace)}" }; _verticalLines.Add(line); var xLabels = ""; if (counter < numXLabels) { xLabels = XAxisLabels[counter]; } var lineValue = new SvgText() { X = x, Y = boundHeight - 2, Value = xLabels }; _verticalValues.Add(lineValue); startGridX += gridXUnits; x += horizontalSpace; } //Bars var colorcounter = 0; double barsPerSeries = 0; foreach (var item in _series) { double gridValueX = horizontalStartSpace + barsPerSeries; double gridValueY = boundHeight - verticalStartSpace; foreach (var dataLine in item.Data) { var dataValue = ((double)dataLine) * verticalSpace / gridYUnits; var gridValue = gridValueY - dataValue; var bar = $"M {ToS(gridValueX)} {ToS(gridValueY)} L {ToS(gridValueX)} {ToS(gridValue)}"; gridValueX += horizontalSpace; var line = new SvgPath() { Index = colorcounter, Data = bar }; _bars.Add(line); } barsPerSeries += 10; var legend = new SvgLegend() { Index = colorcounter, Labels = item.Name }; colorcounter++; _legends.Add(legend); } }
protected override void OnParametersSet() { base.OnParametersSet(); HorizontalLines.Clear(); VerticalLines.Clear(); HorizontalValues.Clear(); VerticalValues.Clear(); Legends.Clear(); ChartLines.Clear(); if (MudChartParent != null) { Series = MudChartParent.ChartSeries; } double maxY = 0.0; int numValues = 0; int numXLabels = XAxisLabels.Length; foreach (var item in Series) { if (numValues < item.Data.Length) { numValues = item.Data.Length; } foreach (int i in item.Data) { if (maxY < i) { maxY = i; } } } double boundHeight = 350.0; double boundWidth = 650.0; double gridYUnits = MudChartParent?.ChartOptions.YAxisTicks ?? 20; double gridXUnits = 30; int numVerticalLines = numValues - 1; int numHorizontalLines = ((int)(maxY / gridYUnits)) + 1; double verticalStartSpace = 25.0; double horizontalStartSpace = 30.0; double verticalEndSpace = 25.0; double horizontalEndSpace = 30.0; double verticalSpace = (boundHeight - verticalStartSpace - verticalEndSpace) / (numHorizontalLines); double horizontalSpace = (boundWidth - horizontalStartSpace - horizontalEndSpace) / (numVerticalLines); //Horizontal Grid Lines double y = verticalStartSpace; double startGridY = 0; for (int counter = 0; counter <= numHorizontalLines; counter++) { SvgPath Line = new SvgPath() { Index = counter, Data = $"M {ToS(horizontalStartSpace)} {ToS((boundHeight - y))} L {ToS((boundWidth - horizontalEndSpace))} {ToS((boundHeight - y))}" }; HorizontalLines.Add(Line); SvgText LineValue = new SvgText() { X = (horizontalStartSpace - 10), Y = (boundHeight - y + 5), Value = ToS(startGridY) }; HorizontalValues.Add(LineValue); startGridY = startGridY + gridYUnits; y = y + verticalSpace; } //Vertical Grid Lines double x = horizontalStartSpace; double startGridX = 0; for (int counter = 0; counter <= numVerticalLines; counter++) { SvgPath Line = new SvgPath() { Index = counter, Data = $"M {ToS(x)} {ToS((boundHeight - verticalStartSpace))} L {ToS(x)} {ToS(verticalEndSpace)}" }; VerticalLines.Add(Line); string xLabels = ""; if (counter < numXLabels) { xLabels = XAxisLabels[counter]; } SvgText LineValue = new SvgText() { X = x, Y = boundHeight - 2, Value = xLabels }; VerticalValues.Add(LineValue); startGridX = startGridX + gridXUnits; x = x + horizontalSpace; } //Chart Lines int colorcounter = 0; foreach (var item in Series) { string chartLine = ""; double gridValueX = 0; double gridValueY = 0; bool firstTime = true; foreach (var line in item.Data) { if (firstTime) { chartLine = chartLine + "M "; firstTime = false; gridValueX = horizontalStartSpace; gridValueY = verticalStartSpace; double gridValue = ((double)line) * verticalSpace / gridYUnits; gridValueY = boundHeight - (gridValueY + gridValue); chartLine = chartLine + ToS(gridValueX) + " " + ToS(gridValueY); } else { chartLine = chartLine + " L "; gridValueX = gridValueX + horizontalSpace; gridValueY = verticalStartSpace; double gridValue = ((double)line) * verticalSpace / gridYUnits; gridValueY = boundHeight - (gridValueY + gridValue); chartLine = chartLine + ToS(gridValueX) + " " + ToS(gridValueY); } } SvgPath Line = new SvgPath() { Index = colorcounter, Data = chartLine }; SvgLegend Legend = new SvgLegend() { Index = colorcounter, Labels = item.Name }; colorcounter = colorcounter + 1; ChartLines.Add(Line); Legends.Add(Legend); } }