Skip to content

Instantly share code, notes, and snippets.

@rjcorwin
Last active October 6, 2021 14:40
Show Gist options
  • Save rjcorwin/6ab3728643a15058c37a2502d59959e2 to your computer and use it in GitHub Desktop.
Save rjcorwin/6ab3728643a15058c37a2502d59959e2 to your computer and use it in GitHub Desktop.
import { Plotly } from 'plotly'
// Copy plotly-styles.js to your project from this gist: https://gist.github.com/rjsteinert/751901de6aca5804b1024c6737e9dc97
import { plotlyStyles } from './plotly-styles.js'
import { LitElement, html } from 'lit-element'
class LitElementBarChart extends LitElement {
static get styles() {
return [
plotlyStyles
]
}
render() {
return html`
<style>
#myDiv {
width: 800px;
height: 800px;
}
</style>
<div id="myDiv"></div>
`
}
updated() {
this.data = [
{
x: ['giraffes', 'orangutans', 'monkeys'],
y: [20, 14, 23],
type: 'bar'
}
];
Plotly.newPlot(this.shadowRoot.querySelector('#myDiv'), this.data);
}
}
customElements.define('lit-element-bar-chart', LitElementBarChart);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment