-
-
Save craigvgw/8fad2be785fb480503ec52dfbcafb916 to your computer and use it in GitHub Desktop.
blazor_pixijs_linechart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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