AngularJs: How to group data based on average of weeks for a month?
I have a function which plots data for 90 days on a chart using C3.js library. I have the start date and end date defined based on the the count variable. Is there any way in which I can group data for 90 days based on week. 1 week = 1 data point (average of 7 days). 4 weeks = 4 data points Likewise. 90 days = 12 data points and so on.
function draw__chart(model, type)
var count = 0
if(type == 'week')
count = 7;
else if (type == 'month')
dcount = 30;
else if (type == '3_months')
count = 90;
$scope.end_daterange = new Date();
$scope.end_daterange = moment($scope.end_daterange).format('MM/DD/YYYY')
$scope.begin_daterange = new Date($scope.end_daterange);
$scope.begin_daterange.setDate($scope.begin_daterange.getDate()- count);
$scope.begin_daterange = moment($scope.begin_daterange).format('MM/DD/YYYY')
$date_id = ["date_id"];
$volume1 = ["volume1"];
$volume2 = ["volume2"];
angular.forEach(model, function(value, key)
//Date for Chart
if(dateCheck($scope.begin_daterange,$scope.end_daterange,moment(value.log_date_id).format('MM/DD/YYYY')))
$date_id.push(moment(value.log_date_id).format('MM/DD/YYYY'));
$volume1.push(value.volume1);
$volume2.push(value.volume2);
);
//Drawing Second Chart
d3.select("#volume_graph svg").remove();
setTimeout(function()
$scope.volume_id = c3.generate(
bindto: d3.select('#volume_graph'),
data:
x : 'date_id',
columns: [
$date_id,
],
,
,
axis:
x:
type: 'category',
tick:
rotate: -90,
multiline: false
,
height: 70
,
y:
label:
text: 'Percentage',
position: 'outer-middle'
,
,
tooltip:
show: true
);
, 100);
};
Function to validate Date range:
function dateCheck(from,to,check)
var fDate,lDate,cDate;
fDate = Date.parse(from);
lDate = Date.parse(to);
cDate = Date.parse(check);
if((cDate <= lDate && cDate >= fDate))
return true;
return false;
;
HTML:
<div id="volume_graph" ng-hide="loading"></div>
javascript angularjs d3.js c3.js
add a comment |
I have a function which plots data for 90 days on a chart using C3.js library. I have the start date and end date defined based on the the count variable. Is there any way in which I can group data for 90 days based on week. 1 week = 1 data point (average of 7 days). 4 weeks = 4 data points Likewise. 90 days = 12 data points and so on.
function draw__chart(model, type)
var count = 0
if(type == 'week')
count = 7;
else if (type == 'month')
dcount = 30;
else if (type == '3_months')
count = 90;
$scope.end_daterange = new Date();
$scope.end_daterange = moment($scope.end_daterange).format('MM/DD/YYYY')
$scope.begin_daterange = new Date($scope.end_daterange);
$scope.begin_daterange.setDate($scope.begin_daterange.getDate()- count);
$scope.begin_daterange = moment($scope.begin_daterange).format('MM/DD/YYYY')
$date_id = ["date_id"];
$volume1 = ["volume1"];
$volume2 = ["volume2"];
angular.forEach(model, function(value, key)
//Date for Chart
if(dateCheck($scope.begin_daterange,$scope.end_daterange,moment(value.log_date_id).format('MM/DD/YYYY')))
$date_id.push(moment(value.log_date_id).format('MM/DD/YYYY'));
$volume1.push(value.volume1);
$volume2.push(value.volume2);
);
//Drawing Second Chart
d3.select("#volume_graph svg").remove();
setTimeout(function()
$scope.volume_id = c3.generate(
bindto: d3.select('#volume_graph'),
data:
x : 'date_id',
columns: [
$date_id,
],
,
,
axis:
x:
type: 'category',
tick:
rotate: -90,
multiline: false
,
height: 70
,
y:
label:
text: 'Percentage',
position: 'outer-middle'
,
,
tooltip:
show: true
);
, 100);
};
Function to validate Date range:
function dateCheck(from,to,check)
var fDate,lDate,cDate;
fDate = Date.parse(from);
lDate = Date.parse(to);
cDate = Date.parse(check);
if((cDate <= lDate && cDate >= fDate))
return true;
return false;
;
HTML:
<div id="volume_graph" ng-hide="loading"></div>
javascript angularjs d3.js c3.js
You can find an anwer to your probleme here: stackoverflow.com/questions/20630676/…
– Lamari Alaa
Nov 15 '18 at 21:38
add a comment |
I have a function which plots data for 90 days on a chart using C3.js library. I have the start date and end date defined based on the the count variable. Is there any way in which I can group data for 90 days based on week. 1 week = 1 data point (average of 7 days). 4 weeks = 4 data points Likewise. 90 days = 12 data points and so on.
function draw__chart(model, type)
var count = 0
if(type == 'week')
count = 7;
else if (type == 'month')
dcount = 30;
else if (type == '3_months')
count = 90;
$scope.end_daterange = new Date();
$scope.end_daterange = moment($scope.end_daterange).format('MM/DD/YYYY')
$scope.begin_daterange = new Date($scope.end_daterange);
$scope.begin_daterange.setDate($scope.begin_daterange.getDate()- count);
$scope.begin_daterange = moment($scope.begin_daterange).format('MM/DD/YYYY')
$date_id = ["date_id"];
$volume1 = ["volume1"];
$volume2 = ["volume2"];
angular.forEach(model, function(value, key)
//Date for Chart
if(dateCheck($scope.begin_daterange,$scope.end_daterange,moment(value.log_date_id).format('MM/DD/YYYY')))
$date_id.push(moment(value.log_date_id).format('MM/DD/YYYY'));
$volume1.push(value.volume1);
$volume2.push(value.volume2);
);
//Drawing Second Chart
d3.select("#volume_graph svg").remove();
setTimeout(function()
$scope.volume_id = c3.generate(
bindto: d3.select('#volume_graph'),
data:
x : 'date_id',
columns: [
$date_id,
],
,
,
axis:
x:
type: 'category',
tick:
rotate: -90,
multiline: false
,
height: 70
,
y:
label:
text: 'Percentage',
position: 'outer-middle'
,
,
tooltip:
show: true
);
, 100);
};
Function to validate Date range:
function dateCheck(from,to,check)
var fDate,lDate,cDate;
fDate = Date.parse(from);
lDate = Date.parse(to);
cDate = Date.parse(check);
if((cDate <= lDate && cDate >= fDate))
return true;
return false;
;
HTML:
<div id="volume_graph" ng-hide="loading"></div>
javascript angularjs d3.js c3.js
I have a function which plots data for 90 days on a chart using C3.js library. I have the start date and end date defined based on the the count variable. Is there any way in which I can group data for 90 days based on week. 1 week = 1 data point (average of 7 days). 4 weeks = 4 data points Likewise. 90 days = 12 data points and so on.
function draw__chart(model, type)
var count = 0
if(type == 'week')
count = 7;
else if (type == 'month')
dcount = 30;
else if (type == '3_months')
count = 90;
$scope.end_daterange = new Date();
$scope.end_daterange = moment($scope.end_daterange).format('MM/DD/YYYY')
$scope.begin_daterange = new Date($scope.end_daterange);
$scope.begin_daterange.setDate($scope.begin_daterange.getDate()- count);
$scope.begin_daterange = moment($scope.begin_daterange).format('MM/DD/YYYY')
$date_id = ["date_id"];
$volume1 = ["volume1"];
$volume2 = ["volume2"];
angular.forEach(model, function(value, key)
//Date for Chart
if(dateCheck($scope.begin_daterange,$scope.end_daterange,moment(value.log_date_id).format('MM/DD/YYYY')))
$date_id.push(moment(value.log_date_id).format('MM/DD/YYYY'));
$volume1.push(value.volume1);
$volume2.push(value.volume2);
);
//Drawing Second Chart
d3.select("#volume_graph svg").remove();
setTimeout(function()
$scope.volume_id = c3.generate(
bindto: d3.select('#volume_graph'),
data:
x : 'date_id',
columns: [
$date_id,
],
,
,
axis:
x:
type: 'category',
tick:
rotate: -90,
multiline: false
,
height: 70
,
y:
label:
text: 'Percentage',
position: 'outer-middle'
,
,
tooltip:
show: true
);
, 100);
};
Function to validate Date range:
function dateCheck(from,to,check)
var fDate,lDate,cDate;
fDate = Date.parse(from);
lDate = Date.parse(to);
cDate = Date.parse(check);
if((cDate <= lDate && cDate >= fDate))
return true;
return false;
;
HTML:
<div id="volume_graph" ng-hide="loading"></div>
javascript angularjs d3.js c3.js
javascript angularjs d3.js c3.js
edited Nov 15 '18 at 21:23
dps
asked Nov 15 '18 at 21:18
dpsdps
356
356
You can find an anwer to your probleme here: stackoverflow.com/questions/20630676/…
– Lamari Alaa
Nov 15 '18 at 21:38
add a comment |
You can find an anwer to your probleme here: stackoverflow.com/questions/20630676/…
– Lamari Alaa
Nov 15 '18 at 21:38
You can find an anwer to your probleme here: stackoverflow.com/questions/20630676/…
– Lamari Alaa
Nov 15 '18 at 21:38
You can find an anwer to your probleme here: stackoverflow.com/questions/20630676/…
– Lamari Alaa
Nov 15 '18 at 21:38
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328027%2fangularjs-how-to-group-data-based-on-average-of-weeks-for-a-month%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328027%2fangularjs-how-to-group-data-based-on-average-of-weeks-for-a-month%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You can find an anwer to your probleme here: stackoverflow.com/questions/20630676/…
– Lamari Alaa
Nov 15 '18 at 21:38