Created
July 9, 2013 15:29
-
-
Save arisetyo/5958305 to your computer and use it in GitHub Desktop.
Setting up Chart.js line chart, with Knockout.js
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> | |
| <script src="js/jquery-1.9.1.js"></script> | |
| <script src="js/knockout-2.1.0.js"></script> | |
| <script src="js/Chart.js"></script> | |
| </head> | |
| <body> | |
| <div> | |
| <canvas id="canvas" height="450" width="600"></canvas> | |
| </div> | |
| <script type="text/javascript"> | |
| function MainViewModel(data) { | |
| var self = this; | |
| self.lineChartData = ko.observable({ | |
| labels : ["January","February","March","April","May","June","July"], | |
| datasets : [ | |
| { | |
| fillColor : "rgba(220,220,220,0.5)", | |
| strokeColor : "rgba(220,220,220,1)", | |
| pointColor : "rgba(220,220,220,1)", | |
| pointStrokeColor : "#fff", | |
| data : [65,59,90,81,56,55,40] | |
| }, | |
| { | |
| fillColor : "rgba(151,187,205,0.5)", | |
| strokeColor : "rgba(151,187,205,1)", | |
| pointColor : "rgba(151,187,205,1)", | |
| pointStrokeColor : "#fff", | |
| data : [28,48,40,19,96,27,100] | |
| } | |
| ] | |
| }); | |
| self.initLine = function() { | |
| var ctx = $("#canvas").get(0).getContext("2d"); | |
| var myLine = new Chart(ctx).Line( vm.lineChartData() ); | |
| } | |
| } | |
| var vm = new MainViewModel(); | |
| ko.applyBindings(vm); | |
| vm.initLine(); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment