我有一个打包的气泡图,我想将气泡深入到散点图。另外,作为奖励,我希望能够将主气泡深入到散点图,该散点图是所有散点图的混合,我不确定这是否可能。
我正在使用 React 构建此代码。现在。向下钻取时,散点图未渲染。
我的代码:
component.js
import React, { useEffect, useState } from "react";
import { Spinner } from "react-bootstrap";
import "bootstrap/dist/css/bootstrap.min.css";
import ScatterChart from "./scatter";
import "./App.css";
const ScatterComponent = ({ data, filteredData }) => {
const [loading, setLoading] = useState(true);
const chartData = filteredData.length !== 0 ? filteredData : data;
const bubbleSeries = [{"name":"ABC","data":[{"name":"page_views","value":6652301,
"drilldown":"ABC - page_views"},{"name":"article_views","value":4812992,"drilldown":"ABC - article_views"},
{"name":"visits","value":5116176,"drilldown":"ABC - visits"},]},
{"name":"XYZ","data":[{"name":"page_views","value":16448241,"drilldown":"XYZ - page_views"},
{"name":"article_views","value":10791478,"drilldown":"XYZ - article_views"},
{"name":"visits","value":11921915,"drilldown":"XYZ - visits"},]}];
const scatterSeries = [{"type":"scatter","id":"ABC - page_views",
"data":[["2024-02-27T00:00:00.000Z",1],["2024-02-26T00:00:00.000Z",1],["2024-02-27T00:00:00.000Z",1],["2024-02-28T00:00:00.000Z",1]],},
{"type":"scatter","id":"ABC - article_views",
"data":[["2024-02-27T00:00:00.000Z",1],["2024-02-26T00:00:00.000Z",1],["2024-02-27T00:00:00.000Z",1],["2024-02-28T00:00:00.000Z",1]],},
{"type":"scatter","id":"ABC - visits",
"data":[["2024-02-27T00:00:00.000Z",1],["2024-02-26T00:00:00.000Z",1],["2024-02-27T00:00:00.000Z",1],["2024-02-28T00:00:00.000Z",1]],},
{"type":"scatter","id":"XYZ - page_views",
"data":[["2024-02-27T00:00:00.000Z",1],["2024-02-26T00:00:00.000Z",1],["2024-02-27T00:00:00.000Z",1],["2024-02-28T00:00:00.000Z",1]],},
{"type":"scatter","id":"XYZ - article_views",
"data":[["2024-02-27T00:00:00.000Z",1],["2024-02-26T00:00:00.000Z",1],["2024-02-27T00:00:00.000Z",1],["2024-02-28T00:00:00.000Z",1]],},
{"type":"scatter","id":"XYZ - visits",
"data":[["2024-02-27T00:00:00.000Z",1],["2024-02-26T00:00:00.000Z",1],["2024-02-27T00:00:00.000Z",1],["2024-02-28T00:00:00.000Z",1]],},
]
useEffect(() => {
const delay = setTimeout(() => {
setLoading(false);
}, 2000);
return () => clearTimeout(delay);
}, []);
return (
<div className="bubbleScatterTrends clearfix w-100 column">
<h3 className="mt-1 ms-1" style={{ color: "#81b0d2" }}>
<u>ABC-XYZ Breakdowns</u>
</h3>
{loading ? (
<div className="text-center">
<Spinner animation="border" variant="primary" />
<Spinner animation="border" variant="secondary" />
<Spinner animation="border" variant="success" />
<Spinner animation="border" variant="danger" />
<Spinner animation="border" variant="warning" />
<Spinner animation="border" variant="info" />
<Spinner animation="border" variant="light" />
<Spinner animation="border" variant="dark" />
</div>
) : (
<div className="clearfix w-100 column">
<div className="clearfix w-100 column">
<div className="w-100 bubbleScatterCharts">
<ScatterChart
bubbleData={bubbleSeries}
scatterData={scatterSeries}
/>
</div>
</div>
</div>
)}
</div>
);
};
export default ScatterComponent;
scatter.js
import React, { useMemo } from "react";
import Highcharts from "highcharts";
import HighchartsReact from "highcharts-react-official";
import highchartsAccessibility from "highcharts/modules/accessibility";
import highchartsExporting from "highcharts/modules/exporting";
import highchartsExportData from "highcharts/modules/export-data";
import highchartsPackedbubble from "highcharts/highcharts-more";
import dayjs from "dayjs";
import "dayjs/locale/es";
highchartsAccessibility(Highcharts);
highchartsExporting(Highcharts);
highchartsExportData(Highcharts);
highchartsPackedbubble(Highcharts);
const ScatterChart = ({ bubbleData, scatterData }) => {
dayjs.locale("en");
const addCommas = (x) =>
x.toString().replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ",");
const options = useMemo(
() => ({
chart: {
type: "packedbubble",
backgroundColor: "#283347",
},
exporting: {
enabled: true,
},
navigation: {
buttonOptions: {
verticalAlign: "top",
y: -10,
x: -5,
},
},
accessibility: {
enabled: false,
},
credits: {
enabled: false,
},
legend: {
enabled: true,
itemStyle: {
color: "#fff",
},
},
tooltip: {
backgroundColor: "#283347",
style: { color: "#fff" },
formatter: function () {
if (this.y !== undefined || this.key !== undefined) {
let tooltip = `<span><b><u>${this.key}</u></b>: ${addCommas(
this.y
)}</span>`;
return tooltip;
}
},
useHTML: true,
},
plotOptions: {
packedbubble: {
minSize: "20%",
maxSize: "100%",
zMin: 0,
zMax: 1000,
layoutAlgorithm: {
gravitationalConstant: 0.05,
splitSeries: true,
seriesInteraction: false,
dragBetweenSeries: true,
parentNodeLimit: true,
},
dataLabels: {
enabled: true,
format: "{point.name}",
filter: {
property: "y",
operator: ">",
value: 250,
},
style: {
color: "black",
textOutline: "none",
fontWeight: "normal",
},
},
},
},
series: bubbleData,
drilldown: {
series: scatterData,
},
}),
[bubbleData, scatterData]
);
return <HighchartsReact highcharts={Highcharts} options={options} />;
};
export default ScatterChart;
我的散点图未渲染。
我在 React 中创建了一个 Packedbubble 演示,其中包含钻取散点图。请看一下,如果您还有任何疑问,请告诉我。
演示: https://stackblitz.com/edit/react-16gsxb?file=style.css,index.js