Skip to content

Instantly share code, notes, and snippets.

function renderChart(data, labels) {
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'This week',
data: data,
}]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Exploring Chart.js</title>
</head>
<style>
function float2dollar(value){
return "U$ "+(value).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
}
function renderChart(data, labels) {
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
@andregardi
andregardi / data.json
Last active September 28, 2018 22:16
{
"chartData": {
"labels": [
"sunday",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday"
function getChartData() {
$("#loadingMessage").html('<img src="./giphy.gif" alt="" srcset="">');
$.ajax({
url: "http://localhost:3000/chartdata",
success: function (result) {
$("#loadingMessage").html("");
var data = [];
data.push(result.thisWeek);
data.push(result.lastWeek);
var labels = result.labels;
<style>
.container {
width: 50%;
height: 50%;
position: relative;
}
#loadingMessage{
position: absolute;
left: 50%;
top: 50%;
{
"chartData": {
"labels": [
"sunday",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday"
function float2dollar(value) {
return "U$ " + (value).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
}
function renderChart(data, labels) {
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
var labels = [
"Vote for blue",
"vote for red",
];
var data = [
70,
30,
];
var pie = document.getElementById("pieChart").getContext('2d');
var myChart = new Chart(pie, {
var labels = [
"sunday",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday"
];