Permalink
Browse files

doc: ChartJS-Sample added

  • Loading branch information...
MikeMitterer committed Dec 5, 2018
1 parent cabb432 commit 209c6d9553acca92e1285536d1d285b7e3e999ab
@@ -8,8 +8,12 @@
<title>{{title}}</title>

<link id="theme" rel="stylesheet" href="packages/prettify/styles/sons-of-obsidian.css">
<!-- For m4d_include -->
<script type="text/javascript" src="packages/prettify/js/prettify.js"></script>

<!-- For m4d_chartjs -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.js"></script>

<!-- Add to homescreen for Chrome on Android -->
<meta name="mobile-web-app-capable" content="yes">
<link rel="icon" sizes="192x192" href="packages/mdl/assets/images/touch/chrome-touch-icon-192x192.png">
@@ -0,0 +1,6 @@
# Analyzer options:
# https://www.dartlang.org/guides/language/analysis-options
#
analyzer:
strong-mode: true

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,95 @@
html, body {
margin: 0;
padding: 0;
}

h1, h2 {
font-family: 'Roboto','Helvetica','Arial',sans-serif;
font-weight: 400;
}

h2 {
font-size: 24px;
line-height: 1.35;

margin-top: 0.66em;
margin-bottom: 0.66em;
}


.ribbon {
width: 100%;
height: 30vh;
}

.demo-page > .mdl-layout__container > .mdl-layout > * {
flex-shrink: 0;
}

.demo-page > .mdl-layout__container > .mdl-layout > main.mdl-layout__content.mdl-layout__content {
margin-top: -25vh;
}

/*header.mdl-layout__header {*/
/*display: flex !important;*/
/*}*/

.container {
max-width: 1600px;
width: 100%;
margin: 0 auto;
}

.content {
border-radius: 2px;
padding: 24px;
}

.mdl-layout__content .demo-section { min-height: 500px; }

.mdl-mini-footer {
padding-top: 12px;
padding-bottom: 12px;
font-size: 12px;
}

#view-source {
position: fixed;
display: block;
right: 0;
bottom: 37px;
margin-right: 40px;
z-index: 900;
}

.sitegen-link, .mm-link { margin-bottom: 0; }
.is-small-screen .sitegen-link .additional-info { display: none; }
.mm-link { font-size: 12px; }

/*
Solves bug in grid...
*/

@media (max-width: 479px) {
.mdl-grid {
padding: 0;
}
}

@media (max-width: 640px) {
.mm-link {
display: none;
}
}

@media (max-width: 839px) and (min-width: 480px) {
.mdl-grid {
padding: 0;
}
}

@media (max-width: 850px) {
#view-source {
bottom: 29px;
}
}
@@ -0,0 +1,7 @@
@import "package:m4d_components/assets/styles/material-design-lite";
@import "_app";

.demo-page--plotly, .demo-section--plotly {


}
@@ -0,0 +1,104 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Material 4 Dart (M4D) is a library of components for web developers based on Google's Material Design, ported to Dart.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CHARTJS</title>

<link id="theme" rel="stylesheet" href="packages/prettify/styles/sons-of-obsidian.css">
<script type="text/javascript" src="packages/prettify/js/prettify.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.js"></script>

<!-- Add to homescreen for Chrome on Android -->
<meta name="mobile-web-app-capable" content="yes">
<link rel="icon" sizes="192x192" href="packages/mdl/assets/images/touch/chrome-touch-icon-192x192.png">

<!-- Add to homescreen for Safari on iOS -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="Material Design Lite">
<link rel="apple-touch-icon-precomposed" href="packages/mdl/assets/images/touch/apple-touch-icon.png">

<!-- Tile icon for Win8 (144x144 + tile color) -->
<meta name="msapplication-TileImage" content="packages/mdl/assets/images/ms-touch-icon-144x144-precomposed.png">
<meta name="msapplication-TileColor" content="#3372DF">

<!-- SEO: If your mobile URL is different from the desktop URL, add a canonical link to the desktop page https://developers.google.com/webmasters/smartphone-sites/feature-phones -->
<!--
<link rel="canonical" href="http://www.example.com/">
-->

<link href='//fonts.googleapis.com/css?family=Roboto:regular,bold,italic,thin,light,bolditalic,black,medium&amp;lang=en' rel='stylesheet' type='text/css'>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

<link rel="stylesheet" href="demo.css">

<style>
div.loading { display: none; }
body.mdl-upgrading > * { display: none; }
body.mdl-upgrading div.loading { display: block; }
header, body { padding: 0; margin: 0; }
</style>

</head>
<body class="demo-page demo-page--chartjs mdl-upgrading" > <div class="loading">Loading...</div>
<div class="mdl-layout mdl-layout--fixed-header mdl-color--grey-100">
<header class="mdl-layout__header mdl-layout__header--scroll mdl-color--grey-100 mdl-color-text--grey-800">
<div class="mdl-layout__header-row">
<span class="mdl-layout-title">CHARTJS-Sample</span>
<div class="mdl-layout-spacer"></div>

</div>
</header>
<div class="ribbon mdl-color--primary"></div>
<main class="mdl-layout__content">
<div class="container mdl-grid">
<div class="mdl-cell mdl-cell--2-col mdl-cell--hide-tablet mdl-cell--hide-phone"></div>
<div class="content mdl-color--white mdl-shadow--4dp content mdl-color-text--grey-800 mdl-cell mdl-cell--8-col">
<section class="demo-section demo-section--chartjs">
<div class="demo-preview-block">
<canvas id="canvas" height="450" width="600"></canvas>
</div>

</section>
</div>
</div>
</main>
<footer class="mdl-mini-footer">
<div class="mdl-mini-footer--left-section">
<div>Sample for pub-package:
<a href="https://pub.dartlang.org/packages/m4d_spa" target="_blank">m4d_spa</a>
<span class="published">/ published: <span class="pubdate">2018-12-05 / 10:36:11</span></span>
</div>
</div>
<div class="mdl-mini-footer--right-section">
<p class="mm-link">Brought to you by:
<a href="http://www.mikemitterer.at/" target="_blank">Mike Mitterer, IT-Consulting and Development Ltd.</a>
</p>
</div>

</footer>
</div>
<a href="https://github.com/MikeMitterer/dart-material-design-lite-site/tree/master/samples/spa_chartjs/web" target="_blank" id="view-source">
<button class="mdl-button mdl-button--fab mdl-ripple-effect mdl-button--accent"><i class="material-icons">pageview</i></button>
</a>

<script defer src="main.dart.js"></script>

<!-- Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-64837522-2', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>
@@ -0,0 +1,82 @@
import "dart:html" as dom;
import "dart:async";
import "dart:math" as math;

import 'package:console_log_handler/console_log_handler.dart';

import 'package:m4d_core/m4d_ioc.dart' as ioc;
import 'package:m4d_core/services.dart' as coreService;

import 'package:m4d_core/m4d_core.dart';

import 'package:m4d_components/m4d_components.dart';

import 'package:m4d_spa/m4d_spa.dart';

import 'package:chartjs/chartjs.dart';


class Application extends MaterialApplication {
final Logger _logger = new Logger('main.ChartDemo.Application');


Application() {
}

@override
void run() {
Future.delayed(Duration(seconds: 1),() => _initStats());
}

//- private -----------------------------------------------------------------------------------

void _initStats() {
var rnd = math.Random();
var months = <String>["January", "February", "March", "April", "May", "June"];

final LinearChartData data = LinearChartData(labels: months, datasets: <ChartDataSets>[
ChartDataSets(
label: "My First dataset",
backgroundColor: "rgba(220,220,220,0.2)",
data: months.map((_) => rnd.nextInt(100)).toList()),
ChartDataSets(
label: "My Second dataset",
backgroundColor: "rgba(151,187,205,0.2)",
data: months.map((_) => rnd.nextInt(100)).toList())
]);

final ChartConfiguration config = ChartConfiguration(
type: 'line', data: data, options: ChartOptions(responsive: true));

final Chart chart = Chart(dom.querySelector('#canvas') as dom.CanvasElement, config);

Timer.periodic(Duration(milliseconds: 800),(_) {
data.datasets.first.data[1] = rnd.nextInt(100);
data.datasets.first.data[2] = rnd.nextInt(100);
chart.update();
});

_logger.info("Loaded!");
}
}

main() async {
configLogging(show: Level.INFO);

// Initialize M4D
ioc.IOCContainer.bindModules([
SPAModule(), CoreComponentsModule()
]).bind(coreService.Application).to(Application());;

final MaterialApplication app = await componentHandler().upgrade();

// Reminder - does not work...
// final script = dom.ScriptElement();
// script.async = true;
// script.src = "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.js";
// final otherScripts = dom.document.getElementsByTagName("script");
// otherScripts.last.parentNode.insertBefore(script, otherScripts.last);
// script.onLoad.listen((_) => app.run());

app.run();
}
Oops, something went wrong.

0 comments on commit 209c6d9

Please sign in to comment.