Reputation: 61
I am looking for the following chart in flutter:
Can anyone provide me any solution?
Upvotes: 2
Views: 204
Reputation: 61
//First get X,Y Center and radius
double centerX = width / 2;
double centerY = height / 2;
double radius = width / 2;
const numberOfIntervals=5;
//create axis lines
var axisLinePaint = Paint()
..color = viewPortBorderColor
..style = PaintingStyle.stroke
..strokeWidth=1;
//Gridline Paint
var gridlinePaint = Paint()
..color = gridColor
..strokeWidth = 0.6
..style = PaintingStyle.fill;
canvas.drawArc(Rect.fromLTRB(0, 0, width, height),
getRadiansByAngle(-90), getRadiansByAngle(270), true, axisLinePaint);
// Get gap between intervals
int gap=270~/numberOfIntervals;
now creating gridlines:
for (var i = gap; i <= 270; i += gap) {
var thetaAngle = 0;
label=label+(maxVal~/numberOfIntervals);
if (i <= 90) {
thetaAngle = 270 + i;
} else {
thetaAngle = i - 90;
}
var theta = thetaAngle * (pi / 180);
var offSet=Offset(centerX + radius * cos(theta), centerY + radius * sin(theta));
canvas.drawLine(
offSet,
Offset(centerX, centerY),
gridlinePaint);
}
for radian angle:
double getRadiansByAngle(double angle) {
return (angle * pi / 180);
}
Here is full solution:
https://github.com/MoinHashmi/radial_chart_gridlines
If anyone have another suggestion or solution please post.
Upvotes: 2