1

How to modify series and options, i want to make chart type=treemap on react hooks like this

enter image description here

i have name, user and percent on api.

  {
    "data": [
        {
            "id": "1",
            "name": "Pisces",
            "user": "95",
            "percent": "3.15%",
        },
        {
            "id": "2",
            "name": "Leo",
            "user": "50",
            "percent": "2.35%",
        },
        {
            "id": "3",
            "name": "Capricorn",
            "user": "91",
            "percent": "3.12%",
        }
        ]
    }

and source for apex https://apexcharts.com/docs/chart-types/treemap-chart/

import React, { useState,useEffect } from 'react';
import axios from 'axios';
import './App.css';
import Chart from 'react-apexcharts'
import icUser from './image/profile-user.png'
import icChart from './image/pie-chart.png'

const  App =()=> {
  const [dataUser,setDataUser]=useState([])
  useEffect(() => {    
     axios.get("http://localhost:4000/data")
      .then(response =>{
          setDataUser(response.data)
      }).catch(e => {
          alert(e);
      })
  }, [])
  
 const series = {.....}
 const options = {.....}

 return (
     <div>
     <Chart options={options} series={series} height={350} type="treemap"/>
     </div>
    )
}
export default App
1
  • Can you explain more... about your question ! Commented Dec 30, 2021 at 6:26

1 Answer 1

1

In series you need to pass an array like this, Where x is the name, and y percentage. and In option you can modify the treemap chart like change height, type, plotOptions and more...

const App = () => {
  const [dataUser, setDataUser] = useState([])
  useEffect(() => {
    axios.get("http://localhost:4000/data")
      .then(response => {
        setDataUser(response.data)
      }).catch(e => {
        alert(e);
      })
  }, [])

  const seriesData = [];
  const options = {}

  dataUser.map((val) => {
    seriesData.push(
      {
        x: val.name,   //
        y: val.percent  //
      }
    );
  });

  const series = [{ data: seriesData }];
  return (
    <div>
      <Chart options={options} series={series} height={350} type="treemap" />
    </div>
  )
}
export default App
Sign up to request clarification or add additional context in comments.

7 Comments

how we can put the data from API on series, i have name, user and percent on API
I update my answer, you need to put your data in array pls check
thanks, now i can show the name, but not yet for user and percent like the picture above
You can show user or percentage in Y
you can pass only two parameter in data array x and y !
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.