Transform filter to remove traces on line graph?


#1

I have a line graph with 50 traces that updates from API data. But I’d like to only display the top 10 traces. I understand I can apply a transform to each trace individually, but can I apply one to all of them to only display traces above a certain value or the top 10 values? Thanks!


#2

I’m curious what transform are you using? If I understand correctly, looking for a filter transform over traces?


#3

Sorry, meant to say filter. I used one on a previous bar chart that took an array for its x values:

{
type: ‘filter’,
target: ‘x’,
operation: ‘>’,
value: 10000000
}

But I have 50 different traces for this line chart, so how to apply to all of them?


#4

Bump! Is there a way to apply this filter to all 50 traces on the line graph? Or does it have to be done individually? Thanks!


#5

We don’t expose an easy way to do this, but it should be easy enough to:

var transform = {
  type: 'filter',
  // ... the rest of your filter settings
}

traces.forEach(t => t.transforms = [transform])

/// then plot
Plotly.newPlot('graph', traces)