How change LabelFormat value at y axis in syncfusion charts? - reactjs

I make a chart with React and syncfusion but I dont'know what is the best way to change the y axis values. I solve so I search the id and mannualy write the DOM in useEffect.
But what is the best way I change y axis values in syncfusion charts?
import React, { useEffect } from "react";
import { skillsIcon } from "../data/dummy";
import { GoPrimitiveDot } from "react-icons/go";
import { Stacked, Pie, Button, SparkLine,BackendStacked } from "../components";
import {
earningData,
SparklineAreaData,
ecomPieChartData,
} from "../data/dummy";
import { useStateContext } from "../contexts/ContextProvider";
const Skills = () => {
const {
screenSize,
setScreenSize,
} = useStateContext();
useEffect(() => {
document.getElementById("charts1_AxisLabel_4").innerHTML = "Medior"
document.getElementById("charts1_AxisLabel_3").innerHTML = ""
document.getElementById("charts1_AxisLabel_2").innerHTML = "Junior"
document.getElementById("charts1_AxisLabel_1").innerHTML = ""
document.getElementById("charts1_AxisLabel_0").innerHTML = "Entry"
}, [screenSize,setScreenSize]);
return (
<div>
<h1 className="text-center text-4xl my-10 font-bold">Skills</h1>
<div className="flex m-3 flex-wrap justify-center gap-1 items-center">
{skillsIcon.map((skill) => (
<div
key={skill.title}
className="bg-white dark:text-gray-200 dark:bg-secondary-dark-bg md:w-40
p-4 pt-9 rounded-2xl"
>
<button
type="button"
style={{ color: skill.iconColor, backgroundColor: skill.iconBg }}
className="text-2xl opacity-0.9 rounded-full p-4 hover:drop-shadow-xl"
>
{skill.icon}
</button>
<p className="mt-3">
<span className="text-lg font-semibold">{skill.title}</span>
<span className={`text-sm text-${skill.pcColor} ml-2`}>
{skill.percentage}
</span>
</p>
</div>
))}
</div>
<div className="flex gap-10 flex-wrap justify-center">
<div
className="bg-white dark:text-gray-200
dark:bg-secondary-dark-bg m-3 p-4 rounded-2xl md:w-780"
>
<div className="">
<h2 className="font-semibold text-center text-xl ">
Skills - graph
</h2>
</div>
<div className="mt-10 flex gap-10 flex-wrap justify-center">
<div>
<Stacked height="420px" width="580px" />
</div>
<div>
<BackendStacked height="420px" width="580px" />
</div>
</div>
</div>
</div>
</div>
);
};
export default Skills;

This requirement can be achieved using the chart axisLabelRender event. Please review the code snippet and sample link shared below, which changes axis labels using an event.
export let ylabels = ["Zero", "Twenty", "Fourty", "Sixty","Eighty", "Hundred"];
export let i = 0;
<ChartComponent id='charts' axisLabelRender={this.onAxisLabelRender.bind(this)}>
</ChartComponent>
onAxisLabelRender(args){
if (args.axis.name == "primaryYAxis") {
if(ylabels.length == i)
i =0;
args.text = ylabels[i]+" %";
i++;
}
}
Sample : https://stackblitz.com/edit/react-w6o5wf
Here’a some more relevant information from our Documentation to learn more about the axisLabelRender event.
https://ej2.syncfusion.com/react/documentation/chart/axis-labels/#customizing-specific-point
Please let us know if you have any more questions.

Related

I want to make react-reveal responsive when it in mobile version disable or make another style

import React from "react";
import { pricing } from "../../database";
import { Fade, Zoom } from "react-reveal";
import { PricingCard } from "../Pricing";
const Pricing = () => {
const { email } = pricing;
return (
<div className="flex items-center justify-center mt-40 flex-col dark:text-white">
<Zoom left cascade>
<h1 className="font-bold text-4xl my-3">PRICING</h1>
</Zoom>
<Zoom>
<h2>I will work according to your choice</h2>
</Zoom>
<div className="flex justify-center gap-10 bg-opacity-50 dark:text-white leading-loose ">
<PricingCard />
</div>
</div>
);
};
export default Pricing;
I want Zoom style work in desktop version only and disable on mobile version, I'am using react js and tailwindCSS, hope my react-reveal can use with them
You can use with just css tricky ) Now zoom is working only large (lg) devices
import React from "react";
import { pricing } from "../../database";
import { Fade, Zoom } from "react-reveal";
import { PricingCard } from "../Pricing";
const Pricing = () => {
const { email } = pricing;
return (
<div className="flex items-center justify-center mt-40 flex-col dark:text-white">
<div className="hidden lg:block">
<Zoom left cascade>
<h1 className="font-bold text-4xl my-3">PRICING</h1>
</Zoom>
<Zoom>
<h2>I will work according to your choice</h2>
</Zoom>
</div>
<div className="lg:hidden">
<h1 className="font-bold text-4xl my-3">PRICING</h1>
<h2>I will work according to your choice</h2>
</div>
<div className="flex justify-center gap-10 bg-opacity-50 dark:text-white leading-loose ">
<PricingCard />
</div>
</div>
);
};
export default Pricing;

Uncaught Error: Rendered more hooks than during the previous render

Hello I am developing a page to search for gifs and I get the error when I search for a larger amount of gifs than I asked for the first time, for example if I ask for 15 gisf and then another 15 different gifs I get no error but if I ask for 15 and then 30 the error appears.
The gif grid component:
`
function Gifs(props: any) {
return (
<div className="gifs-container grid grid-cols-1 md:grid-cols-4 gap-5 ">
{props.gifList.map((gif: gif, index: number) => {
const [active, setActive] = useState(false);
return (
//img container
<div
className="gif-box w-[200px] h-[150px] relative text-white"
key={index}
>
{/* Image */}
<img
src={gif.url}
alt={gif.title}
className="w-full h-full object-cover"
/>
{/* Image overlay */}
<div
className="img-overlay absolute w-full h-full opacity-0 top-0 flex flex-col
items-center bg-[rgba(0,0,0,0.6)] transition duration-100 hover:opacity-100
justify-around overflow-hidden"
>
{/* Overlay Tittle */}
<div className="overlay-tittle font-bold text-xl text-center w-[80%]">
{notGif(gif.title)}
</div>
{/* Overlay Buttons */}
<div className="overlay-buttons grid-cols-2 w-[40%] flex justify-between items-center">
<button
className="viewLink w-8 h-8 hover:opacity-60"
onClick={() => {
window.open(gif.url, "_blank");
}}
></button>
<div className={`copyMessage ${active ? "active" : ""}`}>
<button
className="copyLink w-9 h-9 hover:opacity-60"
onClick={() => {
navigator.clipboard.writeText(gif.url);
setActive(true);
setTimeout(() => {
setActive(false);
}, 500);
}}
></button>
</div>
</div>
</div>
</div>
);
})}
</div>
);
}
export default Gifs;
the app component:
function App() {
const [gifList, setGifList] = useState<gif[]>([]);
const [gifCuantity, setGifCuantity] = useState("Cantidad");
const [gifName, setGifName] = useState("");
const setGifCuantityF = (newGifCuantity: string) => {
setGifCuantity(newGifCuantity);
};
const setGifNameF = (newGifName: string) => {
setGifName(newGifName);
};
const setGifListFun = (newGifList: gif[]) => {
setGifList(newGifList);
};
useEffect(() => {
if (gifCuantity !== "Cantidad" && gifName !== "") {
getGfifs(gifName, gifCuantity, setGifListFun);
setGifCuantity("Cantidad");
}
}, [gifName]);
return (
<div className="App">
<div className="h-screen ">
<div className="mx-auto flex flex-col justify-center items-center gap-8">
<Title />
<Browser
gifCuantity={gifCuantity}
setGifCuantityF={setGifCuantityF}
setGifNameF={setGifNameF}
/>
{/* <Cgifs gifList={gifList} /> */}
<Gifs gifList={gifList} />
</div>
</div>
</div>
);
}
`
i think the main proble is on the gifList useState, this is the useState that will contain all the gifs i fetch, so if the useState had array had 15 boxes and then i fetch for 20 gifs the error will say that the 5 new boxes were null before an now they are a useState

Can I append div on button click in react?

I am trying to make a simple hotel reservation web app in react. Here is what I want to achieve. A user selects room, adults, and children in number and reserve he's/her own hotels. The following screenshot depicts exactly what I want to do.
As you see from the above screenshot, when I click children's Increment + button, I wanted to append a div having children and their age. In the above screenshot, as I Incremented children value 2 times Two divs with children and their age has been appended.
I already design the component as follows. I want the logic here to apply.
Here is my Component code, I use tailwindcss for styling
import React, { useState } from "react";
import rateIcon from "../../../assets/rate-cons.PNG";
import {
CheckIcon,
InformationCircleIcon,
WifiIcon,
ParkingIcon,
HeartIcon,
SwitchVerticalIcon,
AdjustmentsIcon,
MapIcon,
MinusIcon,
PlusIcon,
} from "#heroicons/react/outline";
import mapImage from "../../../assets/map.PNG";
import { LocationMarkerIcon } from "#heroicons/react/solid";
import DatePickers from "../DatePicker/DatePicker";
import {
HotelOutlined,
PeopleAltOutlined,
RoomOutlined,
RoomService,
} from "#material-ui/icons";
import {
ChildFriendly,
FamilyRestroomOutlined,
FamilyRestroomRounded,
} from "#mui/icons-material";
const Hero = () => {
const [rooms, setRooms] = useState(0);
const [show, setShow] = useState(false);
const showGuestInfo = () => setShow(!show);
const addRooms = () => {
setRooms(rooms + 1);
};
const removeRooms = () => {
if (rooms > 1) {
setRooms(rooms - 1);
} else {
setRooms(rooms);
}
};
return (
<div className="p-3 flex w-full flex flex-col relative">
<div className="flex flex-col border-b border-gray">
<div className="p-2 flex justify-between items-center ">
<div className="flex text-sm items-center space-x-2">
<HotelOutlined />
<p>Rooms</p>
</div>
<div className="flex space-x-4 border p-2">
<p>
<MinusIcon
// onClick={removeRooms}
className="bg-gray-light h-6 cursor-pointer"
/>
</p>
<p>{rooms}</p>
<PlusIcon
// onClick={addRooms}
className=" bg-gray-light h-6 cursor-pointer"
/>
</div>
</div>
<div className="p-2 flex justify-between items-center">
<div className="flex text-sm items-center space-x-2">
<PeopleAltOutlined />
<p>Adults</p>
</div>
<div className="flex space-x-4 border p-2">
<p>
<MinusIcon
// onClick={removeRooms}
className="h-6 bg-gray-light cursor-pointer"
/>
</p>
<p>{rooms}</p>
<PlusIcon
// onClick={addRooms}
className="h-6 bg-gray-light cursor-pointer"
/>
</div>
</div>
<div className="p-2 flex justify-between items-center">
<div className="flex text-sm items-center space-x-2">
<FamilyRestroomOutlined />
<p>Childrens</p>
</div>
<div className="flex space-x-4 border p-2">
<p>
<MinusIcon
onClick={removeRooms}
className="h-6 bg-gray-light cursor-pointer"
/>
</p>
<p>{rooms}</p>
<PlusIcon
onClick={addRooms}
className="h-6 bg-gray-light cursor-pointer"
/>
</div>
</div>
</div>
<div className="border-t p-2 border-gray ">
<button className="p-2 border-t border-gray bg-black w-full text-white">
Update
</button>
</div>
</div>
);
};
How can I build this logic?
The correct way to do this in React is to set the state of your component (or its parent). Then when you render the component, you use the state to decide what to render. So you don't "append" a div as much as you decide that you need a div at a certain spot due to the state.
In this case, you might have a list of children's ages as state. Clicking on the + button will add an element to this list, probably defaulting to 0. Then for each child's age, you render a <div> and a <select> with that age. If the age is 0, then you have a message telling the user to select an age. When the user selects an age, you update the list at the correct position with that age.
Note that this can be implemented as a separate component to simplify the code in the top-level view.
The key thing here is that you never manipulate the DOM directly like you would with pure JavaScript or JQuery. Instead, you keep some data and use it to decide what to render.
Since you don't have example, here is a repro on Stackblitz on how you can do it, and here is the code :
import React, { Component } from 'react';
import { render } from 'react-dom';
const App = () => {
const [children, setChildren] = React.useState(0);
return (
<div>
Children :{' '}
<input
type="number"
value={children}
onChange={(e) => setChildren(Number(e.target.value))}
/>
{Array.from(Array(Number(children)).keys()).map((child, index) => (
<div key={index}>
child of <input type="number" /> years old
</div>
))}
</div>
);
};
render(<App />, document.getElementById('root'));
The state children store the number of children. We then just render as many div as this number by creating an array and mapping over it with this particular line :
Array.from(Array(Number(children)).keys())

TailwindCSS fade in Element on click

So I'm making this app and I need to fade in the menu when I click the button. I have it rendering on click using state, but I can't get it to fade in / fade out on click. When I edit the opacity value inside Chrome Dev Console the transition works fine, but when I want to change it using state it doesn't.
Any help? Thanks in advance!
import React, { useState } from "react";
import { useRouter } from "next/router";
import { MenuIcon, XIcon } from "#heroicons/react/outline";
function Header() {
const router = useRouter();
const [popCard, setPopCard] = useState("hidden");
const [fade, setFade] = useState(true);
const handleMenuClick = () => {
setPopCard("inline-block");
setFade(true);
};
const handleXClick = () => {
setPopCard("hidden");
setFade(false);
};
return (
<div className="text-center">
<header className="sticky z-50 top-0 shadow-md bg-white border-b p-5">
<div className="flex justify-between items-center">
<h1
className="text-6xl text-red-500 cursor-pointer"
onClick={() => router.push("/")}
>
Velvet
</h1>
<MenuIcon
className="h-8 text-red-500 cursor-pointer"
onClick={handleMenuClick}
/>
</div>
</header>
<div
className={
popCard +
" w-[60%] flex-col border my-10 pb-3 rounded-3xl shadow-lg transition duration-300 ease-in-out " +
`${fade === true ? "opacity-100" : "opacity-0"}`
}
>
<div className="flex justify-end">
<XIcon
className="h-6 text-red-500 cursor-pointer mt-2 mr-2 opacity-70"
onClick={handleXClick}
/>
</div>
<div className="space-y-8 text-3xl text-center mt-5 mb-10 text-red-500">
<h1>Contac</h1>
<h1>About Us</h1>
</div>
</div>
</div>
);
}
export default Header;
codesandbox: Sandbox
Just to be clear, I want the menu card to fade in when I click the menu button, and I want the menu card to fade out when I click the close button.
The solution is, you need to add duration, like this:
`transition-all duration-200 ${fade ? "opacity-100" : "opacity-0"}`
Here is my forked sandbox you had given, I've removed extra inline CSS, so it may become evident.
Here is the complete code:
function Header() {
const [popCard, setPopCard] = useState("hidden");
const [fade, setFade] = useState(false);
const handleMenuClick = () => {
setPopCard("inline-block");
setFade(true);
};
const handleXClick = () => {
setPopCard("hidden");
setFade(false);
};
console.log(fade, "fade");
return (
<div className="text-center">
<header className="sticky z-50 top-0 shadow-md bg-white border-b p-5">
<div className="flex justify-between items-center">
<h1 className="text-6xl text-red-500 cursor-pointer">Velvet</h1>
<button
className="text-3xl border rounded-lg px-5"
onClick={handleMenuClick}
>
Menu
</button>
</div>
</header>
<div className="p-10">
<div
className={`transition-all duration-200 ${
fade ? "opacity-100" : "opacity-0"
}`}
>
<div className="flex justify-end">
<button className="mt-2 mr-2 border p-2" onClick={handleXClick}>
Close
</button>
</div>
<div className="space-y-2 text-3xl text-center mt-5 mb-10 mx-5 text-red-500">
<h1>Kontakt</h1>
<h1>O Velvetu</h1>
</div>
</div>
</div>
</div>
);
}
export default Header;
Sandbox: https://codesandbox.io/s/sweet-swartz-mr3nru?file=/pages/index.js:41-1396

How to display data from JSON as flex row in div ReactJS

Here is my code. I want to display data from JSON file as flex-row in div. But what I got is column. I use tailwind to display it as flex-row. Here is the expected output: https://i.stack.imgur.com/f8uAp.jpg
import React, { Component } from "react";
import PostData from "../data/data.json";
class Sneaker extends Component {
state = {};
render() {
return (
<div>
{PostData.map((postDetail) => {
return (
<div className="flex flex-row bg-gray-400 w-2/3 mx-auto mt-10">
<div className="text-center w-1/4 p-2 m-2 bg-white">
<img className="w-64 h-64" src={postDetail.image} alt="" />
<h1>{postDetail.name}</h1>
<h1 className="text-red-500">${postDetail.price}</h1>
</div>
</div>
);
})}
</div>
);
}
}
export default Sneaker;
Try to put the postData loop inside the flex-row div as below
<div className="flex flex-row bg-gray-400 w-2/3 mx-auto mt-10">
{PostData.map((postDetail) => {
return (
<div className="text-center w-1/4 p-2 m-2 bg-white">
<img className="w-64 h-64" src={postDetail.image} alt="" />
<h1>{postDetail.name}</h1>
<h1 className="text-red-500">${postDetail.price}</h1>
</div>
);
})}
</div>
If you want put 3 items in a flex row you can write code like this:
import React, { Component } from "react";
import PostData from "../data/data.json";
const perRow = 3;
class Sneaker extends Component {
state = {};
render() {
return (
<div>
{PostData.map((ignoreIt, i) => {
return i % perRow === 0 ? (
<div
className="flex flex-row bg-gray-400 w-2/3 mx-auto mt-10"
key={i}
>
{PostData.slice(i, i + perRow).map((postDetail, j) => {
return (
<div
className="text-center w-1/4 p-2 m-2 bg-white"
key={i + j}
>
<img className="w-64 h-64" src={postDetail.image} alt="" />
<h1>{postDetail.name}</h1>
<h1>{j}</h1>
<h1 className="text-red-500">${postDetail.price}</h1>
</div>
);
})}
</div>
) : null;
})}
</div>
);
}
}
export default Sneaker;

Categories

Resources