Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to show date labels inside cells #568

Open
snehasd8 opened this issue May 30, 2024 · 0 comments
Open

Unable to show date labels inside cells #568

snehasd8 opened this issue May 30, 2024 · 0 comments

Comments

@snehasd8
Copy link

Screenshot 2024-05-30 at 9 24 22 AM

Below is my code
// src/components/CalendarChart.tsx
import React from "react";
import ReactECharts from "echarts-for-react";
import * as echarts from "echarts";

const generatePollDates = () => {
const polls = [
{ name: "Lok Sabha Elections", startDay: 1, endDay: 5 },
{ name: "Rajya Sabha Elections", startDay: 7, endDay: 12 },
{ name: "State Assembly Elections", startDay: 14, endDay: 18 },
{ name: "Municipal Corporation Elections", startDay: 20, endDay: 25 },
{ name: "Panchayat Elections", startDay: 27, endDay: 29 },
];
return polls.map((poll) => ({
name: poll.name,
startDate: 2024-05-${String(poll.startDay).padStart(2, "0")},
endDate: 2024-05-${String(poll.endDay).padStart(2, "0")},
}));
};

const pollDates = generatePollDates();

const CalendarChart: React.FC = () => {
const data = pollDates.flatMap((poll) => [
{
name: Starts: ${poll.name},
value: [poll.startDate, 1],
itemStyle: { color: "green" },
symbol: "circle",
symbolSize: 10,
},
{
name: Ends: ${poll.name},
value: [poll.endDate, 1],
itemStyle: { color: "red" },
symbol: "circle",
symbolSize: 10,
},
]);

const option = {
tooltip: {
trigger: "item",
formatter: (params: any) => {
return ${params.marker} ${params.name};
},
},
legend: {
data: [
{
name: "Starts",
icon: "circle",
textStyle: { color: "green" },
itemStyle: {
color: "green",
},
},
{
name: "Ends",
icon: "circle",
textStyle: { color: "red" },
itemStyle: {
color: "red",
},
},
],
top: 20,
left: "center",
textStyle: {
fontSize: 14,
},
},
calendar: [
{
top: 80,
left: "center",
orient: "horizontal",
cellSize: ["auto", "auto"],
range: "2024-05",
yearLabel: {
show: true,
},
itemStyle: {
borderWidth: 0.5,
},
cellText: {
formatter: (value: string) => {
const [year, month, day] = value.split("-");
return ${day}-${month};
},
position: "top",
show: true,
},
},
],
series: [
{
name: "Starts",
type: "scatter",
coordinateSystem: "calendar",
data: data.filter((d) => d.name.startsWith("Start")),
symbolSize: 20,
},
{
name: "Ends",
type: "scatter",
coordinateSystem: "calendar",
data: data.filter((d) => d.name.startsWith("End")),
symbolSize: 20,
},
],
};

return (
<ReactECharts
option={option}
// style={{ height: 350, width: "100%" }}
lazyUpdate={true}
className="echarts-for-echarts w-full h-[350px]"
/>
);
};

export default CalendarChart;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant