Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda