voidmatcha commented on code in PR #5257:
URL: https://github.com/apache/zeppelin/pull/5257#discussion_r3294491109
##########
zeppelin-web-angular/projects/zeppelin-react/src/components/visualizations/TableVisualization.tsx:
##########
@@ -75,72 +74,132 @@ export const TableVisualization = ({ result, config }:
TableVisualizationProps)
y: parseFloat(row[1] || '0') || 0
}));
- let chart: Column | Line | Pie | Scatter | null = null;
+ chartRef.current.innerHTML = '';
+
+ let chart: any = null;
let cancelled = false;
- import('@antv/g2plot').then(g2plot => {
+ import('chart.js/auto').then(module => {
if (cancelled || !chartRef.current) return;
+ const Chart = module.Chart || module.default;
+
+ const canvas = document.createElement('canvas');
+ canvas.style.width = '100%';
+ canvas.style.height = '100%';
+ chartRef.current.appendChild(canvas);
+
+ const ctx = canvas.getContext('2d');
+ if (!ctx) return;
+
+ let chartConfig: any = {};
switch (currentMode) {
case 'multiBarChart':
- chart = new g2plot.Column(chartRef.current, {
- data,
- xField: 'category',
- yField: 'value',
- color: '#1890ff',
- columnWidthRatio: 0.8
- });
+ chartConfig = {
+ type: 'bar',
+ data: {
+ labels: data.map(d => d.category),
+ datasets: [{
+ label: 'Value',
+ data: data.map(d => d.value),
+ backgroundColor: '#1890ff'
+ }]
+ },
+ options: {
+ responsive: true,
+ maintainAspectRatio: false
+ }
+ };
break;
case 'lineChart':
- chart = new g2plot.Line(chartRef.current, {
- data,
- xField: 'category',
- yField: 'value',
- color: '#1890ff'
- });
+ chartConfig = {
+ type: 'line',
+ data: {
+ labels: data.map(d => d.category),
+ datasets: [{
+ label: 'Value',
+ data: data.map(d => d.value),
+ borderColor: '#1890ff',
+ backgroundColor: 'rgba(24, 144, 255, 0.1)',
+ tension: 0.1
+ }]
+ },
+ options: {
+ responsive: true,
+ maintainAspectRatio: false
+ }
+ };
break;
case 'pieChart':
- chart = new g2plot.Pie(chartRef.current, {
- data,
- angleField: 'value',
- colorField: 'category'
- });
+ chartConfig = {
+ type: 'pie',
+ data: {
+ labels: data.map(d => d.category),
+ datasets: [{
+ data: data.map(d => d.value),
+ backgroundColor: [
+ '#1890ff', '#2fc25b', '#facc14', '#223273', '#8543e0',
'#13c2c2', '#3436c7', '#f04864'
+ ]
+ }]
+ },
+ options: {
+ responsive: true,
+ maintainAspectRatio: false
+ }
+ };
break;
case 'scatterChart':
- chart = new g2plot.Scatter(chartRef.current, {
- data,
- xField: 'x',
- yField: 'y',
- color: '#1890ff'
- });
+ chartConfig = {
+ type: 'scatter',
+ data: {
+ datasets: [{
+ label: 'Value',
+ data: data.map(d => ({ x: d.x, y: d.y })),
+ backgroundColor: '#1890ff'
+ }]
+ },
+ options: {
+ responsive: true,
+ maintainAspectRatio: false,
+ scales: {
+ x: { type: 'linear', position: 'bottom' }
+ }
+ }
+ };
break;
case 'stackedAreaChart':
- chart = new g2plot.Line(chartRef.current, {
- data,
- xField: 'category',
- yField: 'value',
- color: '#1890ff',
- point: {
- size: 3,
- shape: 'circle'
+ chartConfig = {
+ type: 'line',
+ data: {
+ labels: data.map(d => d.category),
+ datasets: [{
+ label: 'Value',
+ data: data.map(d => data.value),
Review Comment:
```suggestion
data: data.map(d => d.value),
```
> Original(master)
<img width="1280" height="633" alt="Image"
src="https://github.com/user-attachments/assets/f55d9fd4-1ab5-474c-8468-28f8e184391d"
/>
> As-Is
<img width="1280" height="633" alt="Image"
src="https://github.com/user-attachments/assets/970159f2-32ea-45af-8747-426c8dad32fa"
/>
> To-Be
<img width="1280" height="633" alt="Image"
src="https://github.com/user-attachments/assets/dfb6e92f-5def-42d8-8948-e12c520ba55a"
/>
The callback references the outer data array instead of the element d, so
data.value is undefined for every row and the Area Chart renders empty.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]