Skip to content

How to create multi line chart with dynamic data? #533

Open
@tobiyas09

Description

@tobiyas09

Question

In victory native legacy I created a Multi Line Chart that would map over a datasets of line data inside VictoryChart

const data = [
[{x: 0, y: 10}, x: 1, y: 11}, x: 2, y: 12}], // <-- first line
[{x: 0, y: 20}, x: 1, y: 21}, x: 2, y: 23}], // <-- second line
[{x: 0, y: 30}, x: 1, y: 31}, x: 2, y: 33}], // <-- third line
]

but now with victory native xl I need to create data array like this

const data = [
{x: 0, y1: 10, y2: 20, y3: 30},
{x: 1, y1: 11, y2: 21, y3: 31}, 
....]

How can I map over the points array inside CartesianChart if I don't know how many lines there will be? In my use case it depends on how many data endpoints the user will select (one or more).

I tried to map over the keys of points from CartesianChartRenderArg but I got nothing.

    {({points, chartBounds}) => (
            <>
              {Object.keys(points).map((k) => {
                return (
                  <Line
                    points={points[k]}
                    color={colors[k]}
                    strokeWidth={2}
                    curveType="catmullRom"
                  />
                );
              })}
            </>
          )}
        </CartesianChart>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions