Playing with Mustache and Google Chart
How do I make an playing with mustache and google chart?
Let's try Mustache and Google Chart.. What is a playing with mustache and google chart? How do you make a playing with mustache and google chart? This script and codes were developed by Renaud Tertrais on 12 August 2022, Friday.
Playing with Mustache and Google Chart - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Playing with Mustache and Google Chart</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <!-- JS -->
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://documentcloud.github.io/underscore/underscore-min.js"></script>
<link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
<script src="http://getbootstrap.com/dist/js/bootstrap.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.7.2/mustache.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<!-- HTML -->
<div id="main">
<form id="add-form"> <input type="text" class="form-control" placeholder="name" name="name" required pattern="\w{3,}"> <div class="btn-group" data-toggle="buttons"> <label class="btn btn-default active"> <input type="radio" name="gender" value="man" checked="checked">Man </label> <label class="btn btn-default"> <input type="radio" name="gender" value="woman"> Woman </label>
</div> <input type="number" class="form-control" style="width:60px" placeholder="25" name="age" required> <input type="submit" class="btn btn-primary" value="add"/> </form> <hr> <div id="view"> <h2>{{friends.length}} friends</h2> <table class="table table-striped table-bordered"> <thead> <tr> <th>Name</th> <th>Gender</th> <th>Age</th> </tr> </thead> <tbody id="friends-list"> <!-- {{#friends}} --> <tr> <td>{{name}}</td> <td class="{{gender}}">{{gender}}</td> <td>{{age}}</td> </tr> <!-- {{/friends}} --> </tbody> </table> </div> <div class="row"> <div class="col-xs-12 col-sm-6"> <h2>Gender :</h2> <div id="chart-gender" class="chart"> <em>Doesn't work in edit mode, go <a href="http://codepen.io/eMaj/full/mvhHb">full page</a> to see the chart.</em> </div> </div> <div class="col-xs-12 col-sm-6"> <h2>Age :</h2> <div id="chart-age" class="chart"> <em>Doesn't work in edit mode, go <a href="http://codepen.io/eMaj/full/mvhHb">full page</a> to see the chart.</em> </div> </div> </div>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Playing with Mustache and Google Chart - Script Codes CSS Codes
#main{ padding:20px; background-color: #EEF; height: 100%; position:absolute; width: 100%;
}
table{ background-color: #fff;
}
table .man{ color:#36C;
}
table .woman{ color:#C31;
}
form .form-control{ display:inline-block; width:inherit;
}
.chart{ min-height:200px;
}
Playing with Mustache and Google Chart - Script Codes JS Codes
// init data
var data = {};
data.friends = [];
data.friends.push({name:'Paul',gender:'man',age:25});
data.friends.push({name:'John',gender:'man',age:18});
data.friends.push({name:'Lucie',gender:'woman',age:14});
//google chart
google.load("visualization", "1", {packages:["corechart"]});
var charts = {};
charts.gender = {};
charts.age = {};
charts.gender.options = { backgroundColor:'none', animation:{ duration: 1000 }, chartArea:{ left:0, top:0, width:"100%", height:"100%" }
};
charts.age.options = { backgroundColor:'none', animation:{ duration: 1000 }, chartArea:{ left:0, top:0, width:"100%", height:"80%" }
};
// init chart function
function initChart(){ //gender charts.gender.chart = new google.visualization.PieChart($('#chart-gender')[0]); //age charts.age.chart = new google.visualization.ColumnChart($('#chart-age')[0]); // call render render();
}
// init Events function
function initEvents(){ $("#add-form").on("submit",function(e){ e.preventDefault(); data.friends.push({ name:$("[name=name]").val(), gender:$("[name=gender]:checked").val(), age:$("[name=age]").val() }); $("[name=name],[name=age]").val(''); render(); });
}
// init Views function
function initViews(){ $view = $("#view"); $view.data().template = $view.html();
}
// render function
function render(){ // gender chart charts.gender.data = new google.visualization.DataTable(); charts.gender.data.addColumn('string','gender'); _.each(data.friends,function(friend){ charts.gender.data.addRow([friend.gender]); }); charts.gender.chart.draw(charts.gender.data, charts.gender.options); //age chart charts.age.data = new google.visualization.DataTable(); charts.age.data.addColumn('number','age'); charts.age.data.addColumn('number','number'); var j = []; /* for(var i = 0 ; i<75 ; i++){ j.push([i,0]); } _.each(data.friends,function(friend){ if(j[friend.age]) j[friend.age][1]++; else j[friend.age] = [friend.age,1]; });*/ j = _.countBy(data.friends,function(friend){ return friend.age; }); var k = []; _.each(j,function(value,key){ k.push([parseInt(key),parseInt(value)]); }); charts.age.data.addRows(k); charts.age.chart.draw(charts.age.data, charts.age.options); // mustache $view = $("#view"); $view.html(Mustache.to_html($view.data().template,data));
}
// onload
$(function(){ initViews(); initEvents(); google.setOnLoadCallback(initChart);
});
Developer | Renaud Tertrais |
Username | renaudtertrais |
Uploaded | August 12, 2022 |
Rating | 3 |
Size | 3,289 Kb |
Views | 30,360 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
React-a11y-range | 7,029 Kb |
Animated logo SVG, CSS3 and JS | 3,432 Kb |
Pure CSS3 arrow icons | 4,030 Kb |
A Pen by Renaud Tertrais | 3,033 Kb |
Flat Blog layout in CSS3 | 4,111 Kb |
Pure CSS albums gallery | 2,978 Kb |
React-draggable | 2,539 Kb |
Images gallery with CSS3 transitions | 2,356 Kb |
Flat CSS3 Breadcrumb | 3,093 Kb |
Angular JS - Basic app | 2,394 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Popover Example | Seanboom | 2,429 Kb |
Simple Accordion | Wearebold | 3,683 Kb |
Reading Grid | Tappily | 4,306 Kb |
Dribbble Template | ExtremelyGinger | 2,204 Kb |
Portfolio Landing Page | FDfranklin | 3,585 Kb |
Animated bar chart | CreativePunch | 3,124 Kb |
Day 11 - Calendar Card | Arnellebalane | 6,984 Kb |
Faux column absolute wrapper | Yurimorini | 1,823 Kb |
Box Shadow Effects | Retrofuturistic | 2,143 Kb |
A Pen by Mohomed Anees | Mohomedanees | 12,597 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!