Microcharts icon indicating copy to clipboard operation
Microcharts copied to clipboard

RadialGaugeChart - Stroke Width is proportional to chart's radio

Open erickvelasco11 opened this issue 6 years ago • 2 comments

I'm reviewing the code for RadialGaugeChart because when I change LineSize the chart change radically.

I'm trying to use a RadialGaugeChart with one Entry, like a CircleBar with percentage, but the stroke is very big, so I change the LineSize, but this change the size of chart proportionaly to LineSize change.

In DrawContent method the LineWidth is calculated automatically with (radius / ((this.Entries.Count() + 1) * 2)) that is good for n circles, but I can't use my own StrokeWidth because lineWidth is used for radiusSpace and radiusSpace is used for calculate entryRadius.

public override void DrawContent(SKCanvas canvas, int width, int height)
{
    this.DrawCaption(canvas, width, height);
    var sumValue = this.Entries.Sum(x => Math.Abs(x.Value));
    var radius = (Math.Min(width, height) - (2 * Margin)) / 2;
    var cx = width / 2;
    var cy = height / 2;
    var lineWidth = (this.LineSize < 0) ? (radius / ((this.Entries.Count() + 1) * 2)) : this.LineSize;
    var radiusSpace = lineWidth * 2;

    for (int i = 0; i < this.Entries.Count(); i++)
    {
        var entry = this.Entries.ElementAt(i);
        var entryRadius = (i + 1) * radiusSpace;
        this.DrawGaugeArea(canvas, entry, entryRadius, cx, cy, lineWidth);
        this.DrawGauge(canvas, entry, entryRadius, cx, cy, lineWidth);
    }
}

I think that the lineWidth and the radiusSpace would be independent, working togheter in automatic case, when LineSize < 0, but allowing to user choose the stroke width and chart size.

Thanks for your comments

erickvelasco11 avatar Mar 05 '19 03:03 erickvelasco11

I had the same idea, use RadialChart with single entry, like a CircleBar with percentage, but that issue is a problem, the LineSize property really changes the chart size, when everything I wanted is just a thin line in a decent sized chart. Did you find a solution to this?

Calvin-2DWeb avatar Mar 14 '19 18:03 Calvin-2DWeb

Can you provide a small repro or code example? There are a lot of issues open that I'm going to try to get through, and not having to build a reproduction myself and guess at certain things would make it go a lot faster. Also, what version of xamarin/Microcharts/android/iOS, etc.

Nixon-Joseph avatar Jul 27 '19 03:07 Nixon-Joseph