Filling area under linerenderer

I have a linerenderer which acts like a graph(i give it ~10-20 (x,y) positions) and I want to fill the area under it. Any idea how to achieve this ? Thanks a lot !

In my opinion a LineRenderer is not very good for filling the area below a graph. Instead, you need a polygon whose lower vertices are aligned to the graph axes, and its upper vertices to the graph line.

In 3D you can use a [dynamically created mesh][1], in 2D probably a sprite whose [vertices you modify][2]. Rough outline of 3D version:

public void CreateFilledGraphShape (Vector3[] linePoints) {
    Vector3[] filledGraphPoints = new Vector3[linePoints.Length * 2]; // one point below each line point
    for (int i = 0; i < linePoints.Length; ++i) {
        filledGraphPoints[2 * i] = new Vector3(linePoints*.x, 0, 0);*

filledGraphPoints[2 * i + 1] = linePoints*;*
}

int numTriangles = (linePoints.Length -1) * 2;
int[] triangles = new int[numTriangles * 3];

int i = 0;
for (int t = 0; t < numTriangles; t += 2) {
// lower left triangle
triangles[i++] = 2 * t;
triangles[i++] = 2 * t +1
triangles[i++] = 2 * t +2;
// upper right triangle - you might need to experiment what are the correct indices
triangles[i++] = 2 * t + 1;
triangles[i++] = 2 * t + 2;
triangles[i++] = 2 * t + 3;
}

// create mesh
Mesh filledGraphMesh = new Mesh();
filledGraphMesh.vertices = filledGraphPoints;
filledGraphMesh.triangles = triangles;
// you might need to assign texture coordinates as well

// create game object and add renderer and mesh to it
GameObject filledGraph = new GameObject(“Filled graph”);
MeshRenderer renderer = filledGraph.AddComponent();
renderer.mesh = mesh;
}
_[1]: https://docs.unity3d.com/ScriptReference/Mesh.html*_
_
[2]: https://docs.unity3d.com/ScriptReference/Sprite-vertices.html*_

Maybe Sprite Shape can solve this problem

At least it helped me in a similar situation

intro-to-2d-world-building-with-sprite-shape

I took @Harinezumi 's code and changed line 14 to 20 where i didt’t muliplied “t” by 2 since it was already muliplied by two on line 12. It work perfectly after that.