Reputation: 28040
I am using angular-google-chart https://github.com/angular-google-chart/angular-google-chart.
The code below works and the chart loads up.
x_axis = {id: "t", label: "Date", type: "string"};
y_axis = {id: "s", label: "Value (%)", type: "number"};
ChartObj.data =
{"cols": [
horizontal_axis,
vertical_axis
],
"rows": [
{c:[{v: 1},{v: 98}]},{c:[{v: 2},{v: 90}]},{c:[{v: 3},{v: 120} ]}
]
};
If I change the x_axis
from string to date type;
x_axis = {id: "t", label: "Date", type: "date"};
the chart does not load and the error appears.
google-visualization-errors-0", message: "c[Me] is not a function
When I checked the documentation https://developers.google.com/chart/interactive/docs/datesandtimes, date type does seem supported. Did I miss out anything? Where can one find an accurate documentation for angular-google-chart? The examples so far seem to be in the form of code examples.
Upvotes: 1
Views: 812
Reputation: 59338
The following example demonstrates how to specify dates using Google Chart Tools AngularJS Directive Module:
angular.module("chartApp", ["googlechart"])
.controller("GenericChartCtrl", function ($scope) {
$scope.chartObject = {};
$scope.chartObject.type = "BarChart";
$scope.chartObject.data = {
"cols": [
{ id: "s", label: "Date", type: "date" },
{ id: "t", label: "Precipitation (mm)", type: "number" },
],
"rows": [
{
c: [
{ v: new Date(2000, 0, 1) },
{ v: 40 },
]
},
{
c: [
{ v: new Date(2000, 1, 2) },
{ v: 50 },
]
},
{
c: [
{ v: new Date(2000, 2, 1) },
{ v: 35 },
]
},
{
c: [
{ v: new Date(2000, 3, 1) },
{ v: 30 },
]
}
]
};
$scope.chartObject.options = {
'title': 'AVERAGE MONTHLY PRECIPITATION OVER THE YEAR (RAINFALL, SNOW)',
vAxis: {
format: 'MMM', //display month part
},
};
});
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.18/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-google-chart/0.0.11/ng-google-chart.js"></script>
<body ng-app='chartApp' ng-controller="GenericChartCtrl">
<div google-chart chart="chartObject" style="height:600px; width:100%;"></div>
</body>
Upvotes: 2