Skip to content

Instantly share code, notes, and snippets.

@yano3nora
Last active March 23, 2024 10:25
Show Gist options
  • Save yano3nora/6abdca893777c7894725603f61028d36 to your computer and use it in GitHub Desktop.
Save yano3nora/6abdca893777c7894725603f61028d36 to your computer and use it in GitHub Desktop.
react-plolty.js

Overview

https://plotly.com/javascript/react/

$ npm i react-plotly.js plotly.js
$ npm i -D @types/react-plotly.js
import React from 'react'
import Plot from 'react-plotly.js'

export const Component = () => (
  <Plot
    config={{ staticPlot: true, responsive: true, autosizable: true }}
    style={{ position: 'absolute', top: 60, left: 60 }}
    layout={{
      width: undefined, // 100%
      height: 500,
      margin: { pad: 0, l: 50, r: 50, t: 50, b: 50 },
      xaxis: { tickfont: { size: 18 } },
      yaxis: { tickfont: { size: 18 } },
      legend: { xanchor: 'center', yanchor: 'bottom', orientation: 'h', x: 0.5, y: -0.2, font: { size: 18 } },
    }}
    data={[
      {
        name: 'Data1',
        type: 'bar',
        x: [1, 2, 3],
        y: [2, 5, 3]
      },
      {
        name: 'Data2',
        type: 'scatter',
        mode: 'lines+markers',
        marker: { color: 'red' },
        x: [1, 2, 3],
        y: [2, 6, 3],
      },
    ]}
  />
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment