@@ -165,30 +165,93 @@ const ChartVisualization = ({
165165 const labels = [ ] ;
166166 const dataPoints = [ ] ;
167167
168- // Se múltiplas colunas, criar rótulos baseados nos nomes das colunas
168+ // Se múltiplas colunas, criar datasets separados para cada coluna
169169 if ( colEnd > colStart ) {
170+ // CORREÇÃO: Em vez de calcular médias, mostrar todos os valores
171+ const datasets = [ ] ;
172+
170173 for ( let colIndex = colStart ; colIndex <= colEnd ; colIndex ++ ) {
171174 const columnName = order [ colIndex ] ?. name ;
172- if ( ! columnName ) {
173- continue ;
174- }
175+ if ( ! columnName ) continue ;
175176
176- labels . push ( columnName ) ;
177+ // Coletar todos os valores desta coluna
178+ const columnValues = [ ] ;
179+ const columnLabels = [ ] ;
177180
178- // Calcular média dos valores desta coluna
179- let sum = 0 ;
180- let count = 0 ;
181181 for ( let rowIndex = rowStart ; rowIndex <= rowEnd ; rowIndex ++ ) {
182182 const value = data [ rowIndex ] ?. attributes [ columnName ] ;
183183 if ( typeof value === 'number' && ! isNaN ( value ) ) {
184- sum += value ;
185- count ++ ;
184+ columnValues . push ( value ) ;
185+ columnLabels . push ( `Row ${ rowIndex + 1 } ` ) ;
186186 }
187187 }
188- dataPoints . push ( count > 0 ? sum / count : 0 ) ;
188+
189+ if ( columnValues . length > 0 ) {
190+ datasets . push ( {
191+ label : columnName ,
192+ data : columnValues ,
193+ backgroundColor : `hsla(${ ( colIndex - colStart ) * 60 } , 70%, 60%, 0.8)` ,
194+ borderColor : `hsl(${ ( colIndex - colStart ) * 60 } , 70%, 50%)` ,
195+ borderWidth : 2 ,
196+ borderRadius : chartType === 'bar' ? 4 : 0 ,
197+ tension : chartType === 'line' ? 0.4 : 0
198+ } ) ;
199+ }
189200 }
201+
202+ // Usar os labels da primeira coluna (todas devem ter o mesmo número de linhas)
203+ for ( let rowIndex = rowStart ; rowIndex <= rowEnd ; rowIndex ++ ) {
204+ labels . push ( `Row ${ rowIndex + 1 } ` ) ;
205+ }
206+
207+ return {
208+ type : 'numberSeries' ,
209+ data : {
210+ labels,
211+ datasets
212+ } ,
213+ options : {
214+ // ...manter as opções existentes...
215+ responsive : true ,
216+ maintainAspectRatio : false ,
217+ interaction : {
218+ intersect : false ,
219+ } ,
220+ plugins : {
221+ title : {
222+ display : true ,
223+ text : 'Selected Data Visualization' ,
224+ font : { size : 16 , weight : 'bold' } ,
225+ color : '#333'
226+ } ,
227+ legend : {
228+ display : datasets . length > 1 // Mostrar legenda se múltiplas colunas
229+ } ,
230+ tooltip : {
231+ backgroundColor : 'rgba(0, 0, 0, 0.8)' ,
232+ titleColor : '#fff' ,
233+ bodyColor : '#fff' ,
234+ borderColor : '#169cee' ,
235+ borderWidth : 1
236+ }
237+ } ,
238+ scales : {
239+ y : {
240+ beginAtZero : true ,
241+ title : { display : true , text : 'Value' , font : { size : 14 , weight : 'bold' } , color : '#555' } ,
242+ grid : { color : 'rgba(0, 0, 0, 0.1)' } ,
243+ ticks : { color : '#666' }
244+ } ,
245+ x : {
246+ title : { display : true , text : 'Categories' , font : { size : 14 , weight : 'bold' } , color : '#555' } ,
247+ grid : { color : 'rgba(0, 0, 0, 0.1)' } ,
248+ ticks : { color : '#666' }
249+ }
250+ }
251+ }
252+ } ;
190253 } else {
191- // Única coluna: usar índices das linhas como rótulos
254+ // Única coluna: usar índices das linhas como rótulos (MANTER COMO ESTÁ)
192255 const columnName = order [ colStart ] ?. name ;
193256 if ( columnName ) {
194257 for ( let rowIndex = rowStart ; rowIndex <= rowEnd ; rowIndex ++ ) {
@@ -197,107 +260,72 @@ const ChartVisualization = ({
197260 dataPoints . push ( typeof value === 'number' && ! isNaN ( value ) ? value : 0 ) ;
198261 }
199262 }
200- }
201263
202- if ( labels . length === 0 || dataPoints . length === 0 ) {
203- return null ;
204- }
264+ if ( labels . length === 0 || dataPoints . length === 0 ) {
265+ return null ;
266+ }
205267
206- return {
207- type : 'numberSeries' ,
208- data : {
209- labels,
210- datasets : [ {
211- label : 'Selected Values' ,
212- data : dataPoints ,
213- backgroundColor : chartType === 'bar'
214- ? dataPoints . map ( ( _ , index ) => `hsla(${ index * 360 / dataPoints . length } , 70%, 60%, 0.8)` )
215- : 'rgba(22, 156, 238, 0.7)' ,
216- borderColor : chartType === 'bar'
217- ? dataPoints . map ( ( _ , index ) => `hsl(${ index * 360 / dataPoints . length } , 70%, 50%)` )
218- : 'rgba(22, 156, 238, 1)' ,
219- borderWidth : 2 ,
220- borderRadius : chartType === 'bar' ? 4 : 0 ,
221- tension : chartType === 'line' ? 0.4 : 0
222- } ]
223- } ,
224- options : {
225- responsive : true ,
226- maintainAspectRatio : false ,
227- interaction : {
228- intersect : false ,
268+ return {
269+ type : 'numberSeries' ,
270+ data : {
271+ labels,
272+ datasets : [ {
273+ label : 'Selected Values' ,
274+ data : dataPoints ,
275+ backgroundColor : chartType === 'bar'
276+ ? dataPoints . map ( ( _ , index ) => `hsla(${ index * 360 / dataPoints . length } , 70%, 60%, 0.8)` )
277+ : 'rgba(22, 156, 238, 0.7)' ,
278+ borderColor : chartType === 'bar'
279+ ? dataPoints . map ( ( _ , index ) => `hsl(${ index * 360 / dataPoints . length } , 70%, 50%)` )
280+ : 'rgba(22, 156, 238, 1)' ,
281+ borderWidth : 2 ,
282+ borderRadius : chartType === 'bar' ? 4 : 0 ,
283+ tension : chartType === 'line' ? 0.4 : 0
284+ } ]
229285 } ,
230- plugins : {
231- title : {
232- display : true ,
233- text : 'Selected Data Visualization' ,
234- font : {
235- size : 16 ,
236- weight : 'bold'
237- } ,
238- color : '#333'
239- } ,
240- legend : {
241- display : false
286+ options : {
287+ responsive : true ,
288+ maintainAspectRatio : false ,
289+ interaction : {
290+ intersect : false ,
242291 } ,
243- tooltip : {
244- backgroundColor : 'rgba(0, 0, 0, 0.8)' ,
245- titleColor : '#fff' ,
246- bodyColor : '#fff' ,
247- borderColor : '#169cee' ,
248- borderWidth : 1
249- }
250- } ,
251- scales : {
252- y : {
253- beginAtZero : true ,
292+ plugins : {
254293 title : {
255294 display : true ,
256- text : 'Value' ,
257- font : {
258- size : 14 ,
259- weight : 'bold'
260- } ,
261- color : '#555'
295+ text : 'Selected Data Visualization' ,
296+ font : { size : 16 , weight : 'bold' } ,
297+ color : '#333'
262298 } ,
263- grid : {
264- color : 'rgba(0, 0, 0, 0.1)'
299+ legend : {
300+ display : false // Uma coluna não precisa de legenda
265301 } ,
266- ticks : {
267- color : '#666'
302+ tooltip : {
303+ backgroundColor : 'rgba(0, 0, 0, 0.8)' ,
304+ titleColor : '#fff' ,
305+ bodyColor : '#fff' ,
306+ borderColor : '#169cee' ,
307+ borderWidth : 1
268308 }
269309 } ,
270- x : {
271- title : {
272- display : true ,
273- text : 'Categories' ,
274- font : {
275- size : 14 ,
276- weight : 'bold'
277- } ,
278- color : '#555'
279- } ,
280- grid : {
281- color : 'rgba(0, 0, 0, 0.1)'
310+ scales : {
311+ y : {
312+ beginAtZero : true ,
313+ title : { display : true , text : 'Value' , font : { size : 14 , weight : 'bold' } , color : '#555' } ,
314+ grid : { color : 'rgba(0, 0, 0, 0.1)' } ,
315+ ticks : { color : '#666' }
282316 } ,
283- ticks : {
284- color : '#666'
317+ x : {
318+ title : { display : true , text : 'Categories' , font : { size : 14 , weight : 'bold' } , color : '#555' } ,
319+ grid : { color : 'rgba(0, 0, 0, 0.1)' } ,
320+ ticks : { color : '#666' }
285321 }
286322 }
287323 }
288- }
289- } ;
324+ } ;
325+ }
290326 }
291327 } , [ selectedData , selectedCells , data , order ] ) ;
292328
293- if ( ! chartData ) {
294- return (
295- < div className = { styles . noData } >
296- < p > Select multiple cells to visualize data</ p >
297- </ div >
298- ) ;
299- }
300-
301329 const renderChart = ( ) => {
302330 if ( chartData . type === 'timeSeries' ) {
303331 return (
0 commit comments