AngularJs: How to group data based on average of weeks for a month?










0















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>









share|improve this question
























  • You can find an anwer to your probleme here: stackoverflow.com/questions/20630676/…

    – Lamari Alaa
    Nov 15 '18 at 21:38















0















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>









share|improve this question
























  • You can find an anwer to your probleme here: stackoverflow.com/questions/20630676/…

    – Lamari Alaa
    Nov 15 '18 at 21:38













0












0








0








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>









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












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
);



);













draft saved

draft discarded


















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















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党