question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding lines dynamically

See original GitHub issue

I would like to know if it’s possible to create lines dynamically.

So this is my chart:

<LineChart data={this.data}>
            <XAxis dataKey="name"/>
            <YAxis/>
            <CartesianGrid strokeDasharray="3 3"/>
            <Tooltip/>
            <Legend />
            <Line type="monotone" dataKey="uv" stroke="#82ca9d" />
</LineChart>

And my data looks like this: [{“channel_id”:1,“date_time”:“2016-08-12 10:22:04”,“value”:43,“created_at”:“2016-10-19 12:26:05”,“updated_at”:“2016-10-19 12:26:05”}, {“channel_id”:2,“date_time”:“2016-08-12 08:49:04”,“value”:14,“created_at”:“2016-10-19 12:26:05”,“updated_at”:“2016-10-19 12:26:05”}, {“channel_id”:2,“date_time”:“2016-08-12 07:44:04”,“value”:29,“created_at”:“2016-10-19 12:26:05”,“updated_at”:“2016-10-19 12:26:05”}]

But than a 1000 more. Now the thing is that I have to create a line for every unique channel_id. But I don’t know the amount of unique channel_id’s on forehand. Side note: The x-axis is for the value and the y-axis is for the date_time.

Your answers are appreciated.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
zifnab87commented, Sep 12, 2017

why not derive the line names directly from data structure? I have unknown list of variables that I would be plotting… so I would like to be able to draw the lines - after I have some of the data received

2reactions
nurgasemeteycommented, Sep 14, 2022

@parassikka77 I’ve done following, previous wasn’t working

<LineChart width={400} height={300} data={this.props.regionData}
    // margin={{ top: 5, right: 30, left: 20, bottom: 5 }}
    >
    <XAxis dataKey="name" />
    <YAxis />
    <CartesianGrid strokeDasharray="3 3" />
    <Tooltip />
    <Legend />
    {/* <Line type="monotone" dataKey="pv" stroke="#8884d8" activeDot={{ r: 8 }} />
    <Line type="monotone" dataKey="uv" stroke="#82ca9d" />
    <Line type="monotone" dataKey="amt" stroke="#82ca9d" /> */}
    {
        this.props.regions.map((region) => {
            return (<Line  name={region.name} key={`line_${region.name}`} stroke={region.color} dataKey={`${region.name}_value`} />)
        })
    }
</LineChart>

As you can see in line where this.props.regions.map, I create Line and assign color(you can randomize)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add/Delete table rows dynamically using JavaScript
Save this question. Show activity on this post. I'm trying to add/delete table rows following this example and this example.
Read more >
Dynamically Add/Remove rows in HTML table using ...
For adding dynamic row in table, we have used insertRow() method. This method will insert a row at position specified by the index...
Read more >
How to Dynamically Add/Remove Table Rows using jQuery
Adding a row: To add a row, define a variable that keeps the count of the total number of that now exists in...
Read more >
How to dynamically add and remove table rows with javascript
In this one, we add remove table rows using a form and javascript. The videos are focused on javascript so I don't go...
Read more >
Dynamically Add and Delete Rows in HTML and JavaScript
This is a small blog post which will provide you the simplest approach to dynamically add and delete rows using javascript and html....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found