@@ -165,30 +165,93 @@ const ChartVisualization = ({
165
165
const labels = [ ] ;
166
166
const dataPoints = [ ] ;
167
167
168
- // Se múltiplas colunas, criar rótulos baseados nos nomes das colunas
168
+ // Se múltiplas colunas, criar datasets separados para cada coluna
169
169
if ( colEnd > colStart ) {
170
+ // CORREÇÃO: Em vez de calcular médias, mostrar todos os valores
171
+ const datasets = [ ] ;
172
+
170
173
for ( let colIndex = colStart ; colIndex <= colEnd ; colIndex ++ ) {
171
174
const columnName = order [ colIndex ] ?. name ;
172
- if ( ! columnName ) {
173
- continue ;
174
- }
175
+ if ( ! columnName ) continue ;
175
176
176
- labels . push ( columnName ) ;
177
+ // Coletar todos os valores desta coluna
178
+ const columnValues = [ ] ;
179
+ const columnLabels = [ ] ;
177
180
178
- // Calcular média dos valores desta coluna
179
- let sum = 0 ;
180
- let count = 0 ;
181
181
for ( let rowIndex = rowStart ; rowIndex <= rowEnd ; rowIndex ++ ) {
182
182
const value = data [ rowIndex ] ?. attributes [ columnName ] ;
183
183
if ( typeof value === 'number' && ! isNaN ( value ) ) {
184
- sum += value ;
185
- count ++ ;
184
+ columnValues . push ( value ) ;
185
+ columnLabels . push ( `Row ${ rowIndex + 1 } ` ) ;
186
186
}
187
187
}
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
+ }
189
200
}
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
+ } ;
190
253
} else {
191
- // Única coluna: usar índices das linhas como rótulos
254
+ // Única coluna: usar índices das linhas como rótulos (MANTER COMO ESTÁ)
192
255
const columnName = order [ colStart ] ?. name ;
193
256
if ( columnName ) {
194
257
for ( let rowIndex = rowStart ; rowIndex <= rowEnd ; rowIndex ++ ) {
@@ -197,107 +260,72 @@ const ChartVisualization = ({
197
260
dataPoints . push ( typeof value === 'number' && ! isNaN ( value ) ? value : 0 ) ;
198
261
}
199
262
}
200
- }
201
263
202
- if ( labels . length === 0 || dataPoints . length === 0 ) {
203
- return null ;
204
- }
264
+ if ( labels . length === 0 || dataPoints . length === 0 ) {
265
+ return null ;
266
+ }
205
267
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
+ } ]
229
285
} ,
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 ,
242
291
} ,
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 : {
254
293
title : {
255
294
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'
262
298
} ,
263
- grid : {
264
- color : 'rgba(0, 0, 0, 0.1)'
299
+ legend : {
300
+ display : false // Uma coluna não precisa de legenda
265
301
} ,
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
268
308
}
269
309
} ,
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' }
282
316
} ,
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' }
285
321
}
286
322
}
287
323
}
288
- }
289
- } ;
324
+ } ;
325
+ }
290
326
}
291
327
} , [ selectedData , selectedCells , data , order ] ) ;
292
328
293
- if ( ! chartData ) {
294
- return (
295
- < div className = { styles . noData } >
296
- < p > Select multiple cells to visualize data</ p >
297
- </ div >
298
- ) ;
299
- }
300
-
301
329
const renderChart = ( ) => {
302
330
if ( chartData . type === 'timeSeries' ) {
303
331
return (
0 commit comments