nicolaskruchten / pivottable

Open-source Javascript Pivot Table (aka Pivot Grid, Pivot Chart, Cross-Tab) implementation with drag'n'drop.
https://pivottable.js.org/
MIT License
4.36k stars 1.08k forks source link

Pivottable clickCallBack / Plot.ly Bar Graph #1048

Open DaveSimmons1234 opened 5 years ago

DaveSimmons1234 commented 5 years ago

Hi there,

Can I click on a plot.ly bar graph and have it return an array of records e.g. like:

pivotData.forEachMatchingRecord(filters, function(record){ int_ids.push(record.int_id); });

Within a clickCallback like method?

This would be super useful.

Thanks a lot for your help. D.

nicolaskruchten commented 5 years ago

This isn’t implemented yet, but in principle shouldn’t be too hard if you want to take a stab at it! :)

On Sat, Nov 10, 2018 at 04:03 DaveSimmons1234 notifications@github.com wrote:

Hi there,

Can I click on a plot.ly bar graph and have it return an array of records e.g. like:

pivotData.forEachMatchingRecord(filters, function(record){ int_ids.push(record.int_id); });

Within a clickCallback like method?

This would be super useful.

Thanks a lot for your help. D.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nicolaskruchten/pivottable/issues/1048, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMbA6zlijDOAnXEVacZlTVVpJOrdi_rks5utpZWgaJpZM4YX5o4 .

DaveSimmons1234 commented 5 years ago

:-) I have tried but a wee pointer in the right direction to get me started would be most appreciated.

D.

miraks31 commented 5 years ago

Hello,

Thanks for pivoting.js, it's really a great tool. I'm also interested in a clickCallBack on graphs. Could you guide me to the solution?

Thank you in advance.

DaveSimmons1234 commented 5 years ago

Hi, I managed to get a working solution in the end using the following:

https://plot.ly/javascript/click-events/

miraks31 commented 5 years ago

Hi Dave,

Thank you for your answer. I'm now able to catch the event when the graph is clicked. But, I didn't find a robust solution to find the associated data of the pivot table. Do you have a solution? Regards.

DaveSimmons1234 commented 5 years ago

Hi there.

So you should have something like

result[0].on('plotly_click', function(data){ 

})

You can then access the data object

result[0].on('plotly_click', function(data){ 
    var selRow = data.points[0].y;
    var selCol = data.points[0].data.name;
})
miraks31 commented 5 years ago

Hi Dave,

Thank you for your answer. With this code: `myPlot[0].on('plotly_click', function(click_data){ console.log(click_data);

let filters = {};

let rows = document.ptablehandler.rows;
let rowsValues = click_data.points[0].data.name.split('-');

for(let i=0; i<rows.length; ++i) {
    filters[rows[i]]=rowsValues[i];
}

let cols = document.ptablehandler.cols;
var colsValues = click_data.points[0].x.split('-');

for(let i=0; i<cols.length; ++i) {
    filters[cols[i]]=colsValues[i];
}                               
debugger

drilldown(click_data.event, click_data.points[0].y, filters, data);

});`

I'm able to build a filter usable in the same function used by clickCallBack. But:

Thank you in advance.

miraks31 commented 5 years ago

Doesn't anyone have an answer? Is it possible to change the values separator "-" by an other character (for example: "|")?