165 lines
3.4 KiB
TypeScript
165 lines
3.4 KiB
TypeScript
"use client";
|
|
import dynamic from "next/dynamic";
|
|
const Chart = dynamic(() => import("react-apexcharts"), { ssr: false });
|
|
import { colors } from "@/lib/colors";
|
|
import { useTheme } from "next-themes";
|
|
import { hexToRGB } from "@/lib/utils";
|
|
import { useConfig } from "@/hooks/use-config";
|
|
import {
|
|
getGridConfig,
|
|
getLabel,
|
|
getYAxisConfig,
|
|
} from "@/lib/appex-chart-options";
|
|
import moment from "moment";
|
|
const MultiSeries = ({ height = 300 }) => {
|
|
const [config] = useConfig();
|
|
const { theme: mode } = useTheme();
|
|
|
|
|
|
|
|
const series = [
|
|
{
|
|
name: "Bob",
|
|
data: [
|
|
{
|
|
x: "Design",
|
|
y: [
|
|
new Date("2019-03-05").getTime(),
|
|
new Date("2019-03-08").getTime(),
|
|
],
|
|
},
|
|
{
|
|
x: "Code",
|
|
y: [
|
|
new Date("2019-03-08").getTime(),
|
|
new Date("2019-03-11").getTime(),
|
|
],
|
|
},
|
|
{
|
|
x: "Test",
|
|
y: [
|
|
new Date("2019-03-11").getTime(),
|
|
new Date("2019-03-16").getTime(),
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "Joe",
|
|
data: [
|
|
{
|
|
x: "Design",
|
|
y: [
|
|
new Date("2019-03-02").getTime(),
|
|
new Date("2019-03-05").getTime(),
|
|
],
|
|
},
|
|
{
|
|
x: "Code",
|
|
y: [
|
|
new Date("2019-03-06").getTime(),
|
|
new Date("2019-03-09").getTime(),
|
|
],
|
|
},
|
|
{
|
|
x: "Test",
|
|
y: [
|
|
new Date("2019-03-10").getTime(),
|
|
new Date("2019-03-19").getTime(),
|
|
],
|
|
},
|
|
],
|
|
},
|
|
];
|
|
const options: any = {
|
|
chart: {
|
|
toolbar: {
|
|
show: false,
|
|
},
|
|
},
|
|
|
|
plotOptions: {
|
|
bar: {
|
|
horizontal: true,
|
|
},
|
|
},
|
|
dataLabels: {
|
|
enabled: true,
|
|
formatter: function (val: [number, number]) {
|
|
var a = moment(val[0]);
|
|
var b = moment(val[1]);
|
|
var diff = b.diff(a, "days");
|
|
return diff + (diff > 1 ? " days" : " day");
|
|
},
|
|
},
|
|
fill: {
|
|
type: "gradient",
|
|
gradient: {
|
|
shade: "light",
|
|
type: "vertical",
|
|
shadeIntensity: 0.5,
|
|
gradientToColors: undefined,
|
|
inverseColors: true,
|
|
opacityFrom: 1,
|
|
opacityTo: 1,
|
|
stops: [50, 0, 100, 100],
|
|
},
|
|
},
|
|
colors: [
|
|
colors.primary,
|
|
colors.info,
|
|
],
|
|
tooltip: {
|
|
theme: mode === "dark" ? "dark" : "light",
|
|
},
|
|
grid: getGridConfig(),
|
|
|
|
xaxis: {
|
|
type: "datetime",
|
|
labels: getLabel(mode === 'light' ? colors["default-600"] : colors["default-300"]),
|
|
axisBorder: {
|
|
show: false,
|
|
},
|
|
axisTicks: {
|
|
show: false,
|
|
},
|
|
},
|
|
yaxis: getYAxisConfig(
|
|
mode === 'light' ? colors["default-600"] : colors["default-300"]
|
|
),
|
|
legend: {
|
|
position: "top",
|
|
labels: {
|
|
colors: mode === 'light' ? colors["default-600"] : colors["default-300"],
|
|
},
|
|
itemMargin: {
|
|
horizontal: 5,
|
|
vertical: 5,
|
|
},
|
|
markers: {
|
|
width: 10,
|
|
height: 10,
|
|
radius: 10,
|
|
offsetX: config.isRtl ? 5 : -5
|
|
}
|
|
},
|
|
padding: {
|
|
top: 0,
|
|
right: 0,
|
|
bottom: 0,
|
|
left: 0,
|
|
},
|
|
};
|
|
return (
|
|
<Chart
|
|
options={options}
|
|
series={series}
|
|
type="rangeBar"
|
|
height={height}
|
|
width={"100%"}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default MultiSeries;
|