UNPKG

@ohdsi/atlascharts

Version:

Visualizations is a collection of JavaScript modules to support D3 visualizations in web-based applications

74 lines (67 loc) 2.05 kB
<html> <head> <title>Visualizations: Lineplot</title> <link href="example.css" rel="stylesheet"> <link href="chart.css" rel="stylesheet"> </head> <body> <h1>Line Plot Example</h1> <div>This plot shows a simple lineplot with multiple series</div> <div style="width:30%" id="plot"></div> <hr/> <div>Data:</div> <textarea id="chartData" style="width:600px; height:400px"> [ { "name":"Ascending", "values":[ {"xValue": 0, "yValue": 1, "id": 1}, {"xValue": 1, "yValue": 2, "id": 1}, {"xValue": 2, "yValue": 4, "id": 1}, {"xValue": 3, "yValue": 7, "id": 1}, {"xValue": 4, "yValue": 9, "id": 1} ]}, { "name":"Descending", "values":[ {"xValue": 0, "yValue": 9, "id": 2}, {"xValue": 1, "yValue": 7, "id": 2}, {"xValue": 2, "yValue": 4, "id": 2}, {"xValue": 3, "yValue": 2, "id": 2}, {"xValue": 4, "yValue": 1, "id": 2} ]}, { "name":"Stable", "values":[ {"xValue": 0, "yValue": 5, "id": 3}, {"xValue": 1, "yValue": 4, "id": 3}, {"xValue": 2, "yValue": 6, "id": 3}, {"xValue": 3, "yValue": 5, "id": 3}, {"xValue": 4, "yValue": 5, "id": 3} ]} ] </textarea> <button id="reload">Reload</button> <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.3/require.min.js"></script> <script src="../build/config.js"></script> <script> requirejs(['atlascharts/line'], function(line) { var cartData; var lineplot = new line(); var target = '#plot'; var seriesColors = { "Ascending": "#00ff00", "Descending": "#ff0000", "Stable": "#0000ff" } function refreshPlot() { chartData = JSON.parse(document.querySelector("#chartData").value); lineplot.render(chartData, target, 300, 300, { ticks: 4, xLabel: "X Value", yLabel: "Y Value", showLegend: true, colors: seriesName => seriesColors[seriesName] }); } document.querySelector("#reload").addEventListener("click", function() { refreshPlot(); }); refreshPlot(); }); </script> </body> </html>