File size: 1,080 Bytes
4a53b35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {
  LitElement,
  html,
} from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
import 'https://cdn.plot.ly/plotly-2.32.0.min.js';

class PlotlyComponent extends LitElement {
  createRenderRoot() {
    return this;
  }

  firstUpdated() {
    this.renderPlot();
  }

  renderPlot() {
    const trace1 = {
      x: [1, 2, 3, 4, 5],
      y: [10, 15, 13, 17, 21],
      type: 'scatter',
      mode: 'lines+markers',
      marker: {color: 'red'},
      name: 'Line 1',
    };

    const trace2 = {
      x: [1, 2, 3, 4, 5],
      y: [16, 5, 11, 9, 8],
      type: 'scatter',
      mode: 'lines+markers',
      marker: {color: 'blue'},
      name: 'Line 2',
    };

    const data = [trace1, trace2];

    const layout = {
      title: 'Simple Line Chart Example',
      xaxis: {
        title: 'X Axis',
      },
      yaxis: {
        title: 'Y Axis',
      },
    };

    Plotly.newPlot(document.getElementById('plot'), data, layout);
  }

  render() {
    return html`<div id="plot"></div>`;
  }
}

customElements.define('plotly-component', PlotlyComponent);