mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-02 08:06:38 +08:00
解决图表数据传递问题
This commit is contained in:
parent
cca33ae16f
commit
d5e05adbe4
@ -1,12 +1,7 @@
|
||||
// "use client";
|
||||
import { Grid, Col, Card, Text, AreaChart, Metric } from "@tremor/react";
|
||||
import UsageAnalysis from "./usage-analysis";
|
||||
// import EchartsComponent from "./testchart";
|
||||
import dynamic from "next/dynamic";
|
||||
|
||||
const UsageByModelChart = dynamic(() => import("./usage-by-model"), {
|
||||
ssr: false,
|
||||
});
|
||||
import UsageByModel from "./usage-by-model";
|
||||
|
||||
export default function AdminPage() {
|
||||
return (
|
||||
@ -16,7 +11,7 @@ export default function AdminPage() {
|
||||
<UsageAnalysis />
|
||||
</Col>
|
||||
<Col numColSpan={1} numColSpanLg={2}>
|
||||
<UsageByModelChart />
|
||||
<UsageByModel />
|
||||
</Col>
|
||||
</Grid>
|
||||
</>
|
||||
|
30
app/app/(admin)/admin/usage-by-model-chart.tsx
Normal file
30
app/app/(admin)/admin/usage-by-model-chart.tsx
Normal file
@ -0,0 +1,30 @@
|
||||
"use client";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import * as echarts from "echarts"; // 导入 echarts
|
||||
|
||||
export default function UsageByModelChart({
|
||||
option,
|
||||
}: {
|
||||
option: echarts.EChartsOption;
|
||||
}) {
|
||||
// const EchartsComponent: React.FC = ({ data: any }) => {
|
||||
// const [option, setOption] = useState({});
|
||||
console.log("======", option);
|
||||
|
||||
useEffect(() => {
|
||||
var chartDom = document.getElementById("usage-by-model-chart");
|
||||
// if (chartDom) echarts.dispose(chartDom);
|
||||
var myChart = echarts.init(chartDom);
|
||||
// console.log('=======[option]', option)
|
||||
option && myChart.setOption(option);
|
||||
}, []); // 空数组作为第二个参数,表示仅在组件挂载和卸载时执行
|
||||
|
||||
return (
|
||||
<div
|
||||
id="usage-by-model-chart"
|
||||
style={{ width: "100%", height: "400px" }}
|
||||
></div>
|
||||
);
|
||||
}
|
||||
|
||||
// export default EchartsComponent;
|
@ -1,63 +1,50 @@
|
||||
"use client";
|
||||
import React, { useEffect } from "react";
|
||||
import * as echarts from "echarts"; // 导入 echarts
|
||||
import * as echarts from "echarts";
|
||||
import { EChartsOption } from "echarts";
|
||||
import dynamic from "next/dynamic";
|
||||
|
||||
// const isBrowser = () => typeof window !== 'undefined'; //The approach recommended by Next.js
|
||||
const UsageByModelChart = dynamic(() => import("./usage-by-model-chart"), {
|
||||
ssr: false,
|
||||
});
|
||||
|
||||
const EchartsComponent: React.FC = () => {
|
||||
useEffect(() => {
|
||||
// if (!isBrowser()) return;
|
||||
var chartDom = document.getElementById("usage-by-model-chart");
|
||||
// if (!chartDiv.current) return;
|
||||
// var myChart = echarts.init(chartDiv.current)
|
||||
var myChart = echarts.init(chartDom);
|
||||
var option;
|
||||
|
||||
option = {
|
||||
title: {
|
||||
text: "Referer of a Website",
|
||||
subtext: "Fake Data",
|
||||
left: "center",
|
||||
},
|
||||
tooltip: {
|
||||
trigger: "item",
|
||||
},
|
||||
legend: {
|
||||
orient: "vertical",
|
||||
left: "left",
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: "Access From",
|
||||
type: "pie",
|
||||
radius: "50%",
|
||||
data: [
|
||||
{ value: 1048, name: "Search Engine" },
|
||||
{ value: 735, name: "Direct" },
|
||||
{ value: 580, name: "Email" },
|
||||
{ value: 484, name: "Union Ads" },
|
||||
{ value: 300, name: "Video Ads" },
|
||||
],
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
shadowBlur: 10,
|
||||
shadowOffsetX: 0,
|
||||
shadowColor: "rgba(0, 0, 0, 0.5)",
|
||||
},
|
||||
export default function UsageByModel() {
|
||||
const usageByModelOption: EChartsOption = {
|
||||
title: {
|
||||
text: "Referer of a Website",
|
||||
subtext: "Fake Data",
|
||||
left: "center",
|
||||
},
|
||||
tooltip: {
|
||||
trigger: "item",
|
||||
},
|
||||
legend: {
|
||||
orient: "vertical",
|
||||
left: "left",
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: "Access From",
|
||||
type: "pie",
|
||||
radius: "50%",
|
||||
data: [
|
||||
{ value: 1048, name: "Search Engine" },
|
||||
{ value: 735, name: "Direct" },
|
||||
{ value: 580, name: "Email" },
|
||||
{ value: 484, name: "Union Ads" },
|
||||
{ value: 300, name: "Video Ads" },
|
||||
],
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
shadowBlur: 10,
|
||||
shadowOffsetX: 0,
|
||||
shadowColor: "rgba(0, 0, 0, 0.5)",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
option && myChart.setOption(option);
|
||||
}, []); // 空数组作为第二个参数,表示仅在组件挂载和卸载时执行
|
||||
|
||||
},
|
||||
],
|
||||
};
|
||||
return (
|
||||
<div
|
||||
id="usage-by-model-chart"
|
||||
style={{ width: "100%", height: "400px" }}
|
||||
></div>
|
||||
<>
|
||||
<UsageByModelChart option={usageByModelOption} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default EchartsComponent;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user