You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@zeppelin.apache.org by "jongyoul (via GitHub)" <gi...@apache.org> on 2026/05/25 02:43:46 UTC

Re: [PR] chore(zeppelin-web-angular): remove @antv/g2plot and migrate to chart.js to fix npm audit [zeppelin]

jongyoul commented on code in PR #5257:
URL: https://github.com/apache/zeppelin/pull/5257#discussion_r3295826354


##########
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),
+                borderColor: '#1890ff',
+                backgroundColor: 'rgba(24, 144, 255, 0.2)',
+                fill: true,
+                tension: 0.1
+              }]
             },
-            lineStyle: {
-              lineWidth: 2
+            options: {
+              responsive: true,
+              maintainAspectRatio: false
             }
-          });
+          };
           break;
       }
 
-      if (chart) {
-        chart.render();
-      }
+      chart = new Chart(ctx, chartConfig);
     });
 
     return () => {
       cancelled = true;
       if (chart) {
         chart.destroy();
       }
+      if (chartRef.current) {
+        chartRef.current.innerHTML = '';
+      }

Review Comment:
   Thanks for the review! I've captured the `chartRef.current` reference into a local `container` variable at the beginning of the effect and updated the effect and cleanup function to use it. This resolves the `react-hooks/exhaustive-deps` warning.



-- 
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: reviews-unsubscribe@zeppelin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org