Skip to content

Instantly share code, notes, and snippets.

@mzsima
Created May 31, 2019 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mzsima/0b9359aa52f5135034804c38075bb800 to your computer and use it in GitHub Desktop.
Save mzsima/0b9359aa52f5135034804c38075bb800 to your computer and use it in GitHub Desktop.
blazor_pixijs_linechart
const app = new PIXI.Application({
width: 200,
height: 200,
backgroundColor: 0xeeeeee,
resolution: window.devicePixelRatio || 1,
});
const graphics = new PIXI.Graphics();
app.stage.addChild(graphics);
window.CreatePIXI = (params) => {
document.getElementById('mypixi').appendChild(app.view);
}
window.DrawLine = (params) => {
graphics.clear();
graphics.lineStyle(2, 0xff0, 1);
for (let i=0; i < params.pts.length; i+=2) {
let x = params.pts[i];
let y = 200 - params.pts[i+1];
if (i == 0) graphics.moveTo(x, y);
else graphics.lineTo(x, y);
}
graphics.endFill();
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>line_chart</title>
<base href="/" />
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="css/site.css" rel="stylesheet" />
</head>
<body>
<app>Loading...</app>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/4.5.1/pixi.min.js"></script>
<script type="text/javascript" src="helper.js"></script>
<script src="_framework/blazor.webassembly.js"></script>
</body>
</html>
@page "/"
@inject IJSRuntime JsRuntime;
<h1>line chart</h1>
<div id="mypixi"></div>
@functions {
bool first = true;
int [] points = new int[] {
0, 120,
50, 120,
100, 20,
150, 90,
200, 0};
protected override async Task OnAfterRenderAsync()
{
if (first) {
first = false;
await JsRuntime.InvokeAsync<object>("CreatePIXI","");
await JsRuntime.InvokeAsync<object>("DrawLine",new { pts = points });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment