Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

306
Views
How to create simple line chart with json response data

I'm fetching price change data from an API endpoint, and I am getting this response from axios

0: (2) [1639382650242, 48759.49757943229]
1: (2) [1639386250855, 49131.24712464529]
2: (2) [1639389730718, 48952.65930253478]
3: (2) [1639393442318, 48821.67463307133]
4: (2) [1639396908986, 48835.214009032316]
5: (2) [1639400493105, 48618.25814914513]
6: (2) [1639404186695, 48572.06354948456]
7: (2) [1639407821756, 47974.48879991822]
8: (2) [1639411648037, 47105.42054562465]
9: (2) [1639414998352, 47176.56337927206]

I tried using this example code from the docs to render a simple line chart but it says that i must have atleast 2 columns of data:

                         <Chart
                            width={'600px'}
                            height={'400px'}
                            chartType="Line"
                            loader={<div>Loading Chart</div>}
                            data={
                                historicData.prices
                            }
                          />

Is there a way to get it to work with google-react-charts?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Add time and price as labels to the first entry. You can convert timestamps to actual date objects.

export default function App() {
  const data = [
    [1639382650242, 48759.49757943229],
    [1639386250855, 49131.24712464529],
    [1639389730718, 48952.65930253478],
    [1639393442318, 48821.67463307133],
    [1639396908986, 48835.214009032316],
    [1639400493105, 48618.25814914513],
    [1639404186695, 48572.06354948456],
    [1639407821756, 47974.48879991822],
    [1639411648037, 47105.42054562465],
    [1639414998352, 47176.56337927206]
  ];

  const processedData = [[{ type: "date", label: "time" }, "price"]].concat(
    data.map(([timestamp, price]) => {
      return [new Date(timestamp), price];
    })
  );

  return (
    <div className="App">
      <Chart
        width={"600px"}
        height={"400px"}
        chartType="Line"
        loader={<div>Loading Chart</div>}
        data={processedData}
      />
    </div>
  );
}

Code sandbox => https://codesandbox.io/s/busy-johnson-1xc0w?file=/src/App.js

about 4 years ago · Juan Pablo Isaza Report

0

React Google line chart exammple

Please check Have you missed this labels in data section as per above image?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!