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

173
Views
How to add second array of data to TinyArea graph in antd?

In a React project, a numeric data is plotted which resembles a graph and that data is displayed at specific points when hovered over the graph. Here the numeric data is in array format but, I need to add second array of data to display the corresponding 'dates' to that data. Any appropriate solution?

Below is the code for reference

const DemoTinyArea: React.FC = () => {
  var data = [
    264, 417, 438, 887, 309, 397, 550, 575, 563, 430, 525, 592
  ];
{/* var data2 = [
    '2021-06-01T00:00:00','2021-07-01T00:00:00', '2021-09-01T00:00:00', '2021-02-01T00:00:00', '2021-03-01T00:00:00', '2021-04-01T00:00:00', '2021-07-01T00:00:00', '2021-01-01T00:00:00', '2021-02-01T00:00:00', '2021-05-01T00:00:00', '2021-08-01T00:00:00', '2021-04-01T00:00:00' 
] */}
  var config = {
    height: 60,
    autoFit: false,
    data: data, // How to append data2 here
    smooth: true,
  };
  return <TinyArea {...config} />;
};

As can be seen from above code, an array of data is plotted but, one more array of data is to be appended to show the 'date' data when hovered. Any optimal solution highly appreciated.

This is codesandbox link: https://codesandbox.io/s/gallant-davinci-0hykv?file=/App.tsx

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

0

The TinyArea component seems to only use a numeric value. If you want to show the corresponding date when hovered you can use a custom tooltip:

import React, { useState, useEffect } from "react";
import { TinyArea } from "@ant-design/charts";

const DemoTinyArea: React.FC = () => {
  var data = [264, 417, 438, 887, 309, 397, 550, 575, 563, 430, 525, 592];
  var data2 = [
    "2021-06-01T00:00:00",
    "2021-07-01T00:00:00",
    "2021-09-01T00:00:00",
    "2021-02-01T00:00:00",
    "2021-03-01T00:00:00",
    "2021-04-01T00:00:00",
    "2021-07-01T00:00:00",
    "2021-01-01T00:00:00",
    "2021-02-01T00:00:00",
    "2021-05-01T00:00:00",
    "2021-08-01T00:00:00",
    "2021-04-01T00:00:00"
  ];
  var config = {
    height: 60,
    autoFit: false,
    data: data,
    tooltip: {
      customContent: (index) => {
        // Format the date
        return <div>{data2[index]}</div>;
      }
    },
    smooth: true
  };
  return <TinyArea {...config} />;
};

export default DemoTinyArea;

You could also consider using another component that can use date for the X-Axis.

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!