Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
ReactJS is there a way to change the title text on an event trigger in a Plotly js plot?

When I create the plot, I give it a layout parameter and I know I can set an x-axis title but I would like to change the x-axis title based on which plot I'm showing based on an event trigger.

Where I create the plot: (Plotting.js)

<Plot
            data={[]}
            revision={this.state.revision}
            config = {{displayModeBar: true, modeBarButtonsToRemove: ["lasso2d", "select2d", "zoom2d", "resetScale2d"], displaylogo: false}}
            layout= {{
              xaxis: {
                range: [State.values.xMin, State.values.xMax],
                title: {
                  text: "The text I'm trying to change is here"
                }
              }
            }}
/>

Where I want to update the plot: (StatisticField.js)

export default function StatisticsDropDown() {
    return (
        <Select onChange={(event) => {
            State.values.PlotInfo.Fields = event.target.value
            //console.log(document.getElementById("updater").innerHTML )
            let e = {target: {value: ""}}
            document.getElementById("min").value = 0
            document.getElementById("max").value = 0
            
            
            if(State.values.PlotInfo.Fields === "1"){
                Plot.layout.title.text = State.values.PlotInfo.Fields + " mA"
            }
            else if(State.values.PlotInfo.Fields === "2"){
                Plot.layout.title.text = State.values.PlotInfo.Fields + " dB"
            }
            else if(State.values.PlotInfo.Fields === "3"){
                Plot.layout.title.text = State.values.PlotInfo.Fields + " dBm"
            }
            else if(State.values.PlotInfo.Fields === "4"){
                Plot.layout.title.text = State.values.PlotInfo.Fields + " ps"
            }
            else if(State.values.PlotInfo.Fields === "5"){
                Plot.layout.title.text = State.values.PlotInfo.Fields + " dBm"
            }
            else if(State.values.PlotInfo.Fields === "6"){
                Plot.layout.title.text = State.values.PlotInfo.Fields + " dB"
            }
            else{
                Plot.layout.title.text = "broken very sad"
            }
            window.testing.createPlot(e)
        }}>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            <option value="6">6</option> 
        </Select>
    );
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to use a state manager so that the component renders again when its value changes.

Capture the selected value StatisticsDropDown by using useState.

const [type, setType] = useState();

For the StatisticsDropDown component, update type value when values changes by:

  <select onChange={(e)= setType(e.target.value)}>
<option value="mA">mA</option>
<option value="dB">dB</option>
</select>

Then, you can set Plot title dynamically reading type value.

<Plot
            data={[]}
            revision={this.state.revision}
            config = {{displayModeBar: true, modeBarButtonsToRemove: ["lasso2d", "select2d", "zoom2d", "resetScale2d"], displaylogo: false}}
            layout= {{
              xaxis: {
                range: [State.values.xMin, State.values.xMax],
                title: {
                  text: type
                }
              }
            }}
/>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!