I have data by date like this there is no 2017/07/17,2017/07/16,2017/07/15
because they are bank holidays.
chartData = new Array();
chartData[0] = new Array();
chartData[0].closePrice = 1207;
chartData[0].date = new Date("2017/07/12");
chartData[1] = new Array();
chartData[1].closePrice = 1227;
chartData[1].date = new Date("2017/07/13");
chartData[2] = new Array();
chartData[2].closePrice = 1216;
chartData[2].date = new Date("2017/07/14");
chartData[3] = new Array();
chartData[3].closePrice = 1234;
chartData[3].date = new Date("2017/07/18");
I use this chartData as dataProvider for making graph.
var dataSet = new AmCharts.DataSet();
dataSet.dataProvider = chartData;
dataSet.categoryField = "date";
chart.dataSets = [dataSet];
var stockPanel = new AmCharts.StockPanel();
stockPanel.title = "Stock Main";
stockPanel.id = "stockPanel";
stockPanel.showCategoryAxis = false;
stockPanel.recalculateToPercents = "never";
var valueAxis = new AmCharts.ValueAxis();
valueAxis.dashLength = 5;
stockPanel.addValueAxis(valueAxis);
stockPanel.categoryAxis.dashLength = 5;
stockPanel.categoryAxis.equalSpacing = true; // it doesn't work ....
var graph = new AmCharts.StockGraph();
graph.type = "line";
graph.valueField = "closePrice";
stockPanel.addStockGraph(graph);
however 2017/07/15,2017/07/16 2017/07/16 are drawn on X axis , even there are no data.
Even .equalSpacing looks in vain.
How can I remove this???
You have to set equalSpacing in the categoryAxesSettings property in the stock chart for it to work.
//object-based setup
chart.categoryAxesSettings = new AmCharts.CategoryAxesSettings();
chart.categoryAxesSettings.equalSpacing = true;
//makeChart version
AmCharts.makeChart("chartdiv", {
// ...
"categoryAxesSettings": {
"equalSpacing": true
},
// ...
});
Demo
Related
I made some charts using chart js and the chart shown is broken like this
my code is like below
var configPBU = configKurvaPBU();
var ctxPBU = document.getElementById('canvasPBU').getContext('2d');
window.myLine = new Chart(ctxPBU, configPBU);
var configBBU = configKurvaBBU();
var ctxBBU = document.getElementById('canvasBBU').getContext('2d');
window.myLine = new Chart(ctxBBU, configBBU);
//SHOW BBPB CHART
let ctxBBPB = document.getElementById('canvasBBPB').getContext('2d');
if (ddlBBPB.includes("CDC")) {
document.getElementById("logoChartBBPB").src = "<%= Page.ResolveClientUrl("~/Images/Icon/logo-cdc.svg") %>";
document.getElementById("SPScoreBBPB").style.display = "none";
let configBBPB = configKurvaCDCBBPB();
window.myLine = new Chart(ctxBBPB, configBBPB);
} else {
document.getElementById("logoChartBBPB").src = "<%= Page.ResolveClientUrl("~/Images/Icon/logo-who.svg") %>";
document.getElementById("SPScoreBBPB").style.display = "inline";
let configBBPB = configKurvaBBPB();
window.myLine = new Chart(ctxBBPB, configBBPB);
}
//END SHOW BBPB CHART
var configLKU = configKurvaLKU();
var ctxLKU = document.getElementById('canvasLKU').getContext('2d');
window.myLine = new Chart(ctxLKU, configLKU);
var configBMI = configKurvaBMI();
var ctxBMI = document.getElementById('canvasBMI').getContext('2d');
window.myLine = new Chart(ctxBMI, configBMI);
why is this happening, and how to solve it??
i have tried to use .destroy()
but it's not working
thanks in advance and sorry for my bad english
I'm a newbie when it comes to coding, so lots to learn from my end. I created the following script which would integrate reoccurring Office Hours from data pulled from Sheets to Calendar. I'm wondering if there is an easier way to do this? How would I be able to include a For Loop for this, since most of them reoccur on different days of the week?
Any help would be appreciated. Thanks!
function officeHoursEventSeries() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = spreadsheet.getLastRow();
var calendarId = spreadsheet.getRange("d2").getValue();
var cal = CalendarApp.getCalendarById(calendarId);
//for 1
var title1 = spreadsheet.getRange("a4").getValue();
var start1 = spreadsheet.getRange("b4").getValue();
var end1 = spreadsheet.getRange("c4").getValue();
var descrip1 = spreadsheet.getRange("d4").getValue();
var reccurence1 = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekday(CalendarApp.Weekday.TUESDAY).until(new Date('December 21,2021'));
cal.createEventSeries(title1,start1,end1,reccurence1,{description: descrip1})
//for 2
var title2 = spreadsheet.getRange("a5").getValue();
var start2 = spreadsheet.getRange("b5").getValue();
var end2 = spreadsheet.getRange("c5").getValue();
var descrip2 = spreadsheet.getRange("d5").getValue();
var reccurence2 = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekday(CalendarApp.Weekday.FRIDAY).until(new Date('December 21,2021'));
cal.createEventSeries(title2,start2,end2,reccurence2,{description: descrip2})
//for 3
var title3 = spreadsheet.getRange("a6").getValue();
var start3 = spreadsheet.getRange("b6").getValue();
var end3 = spreadsheet.getRange("c6").getValue();
var descrip3 = spreadsheet.getRange("d6").getValue();
var reccurence3 = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekdays([CalendarApp.Weekday.MONDAY,CalendarApp.Weekday.WEDNESDAY]).until(new Date('December 21,2021'));
cal.createEventSeries(title3,start3,end3,reccurence3,{description: descrip3})
//for 4
var title4 = spreadsheet.getRange("a7").getValue();
var start4 = spreadsheet.getRange("b7").getValue();
var end4 = spreadsheet.getRange("c7").getValue();
var descrip4 = spreadsheet.getRange("d7").getValue();
var reccurence4 = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekday(CalendarApp.Weekday.TUESDAY).until(new Date('December 21,2021'));
cal.createEventSeries(title4,start4,end4,reccurence4,{description: descrip4})
//for 5
var title5 = spreadsheet.getRange("a8").getValue();
var start5 = spreadsheet.getRange("b8").getValue();
var end5 = spreadsheet.getRange("c8").getValue();
var descrip5 = spreadsheet.getRange("d8").getValue();
var reccurence5 = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekdays([CalendarApp.Weekday.TUESDAY,CalendarApp.Weekday.THURSDAY]).until(new Date('December 21,2021'));
cal.createEventSeries(title5,start5,end5,reccurence5,{description: descrip5})
}
SpreadsheetApp.getActiveSheet().getRange('a4:d8').getValues().forEach(r => {
let title = r[0];
let start = r[1];
let end = r[2];
let descrip = r[4];
//I'll leave recurrence up to you to figure out
cal.createEventSeries(title, start, end, reccurence, { description: descrip });
})
The variables following are defined through a Car prototype:
var Car = function(maker, type, model) {
this.maker = maker;
this.type = type;
this.model = model;
}
var golf = new Car('VW', 'Hatchback', 'Golf');
var sentra = new Car('Nissan', 'Sedan', 'Sentra');
var _328i = new Car('BMW', 'Convertible', "328i");
var gallardo = new Car('Lamborghini', 'Convertible', "Gallardo");
var corniche = new Car('Rolls Royce', 'Sedan', "Corniche");
Car.prototype.year = 0;
golf.year = 2015;
sentra.year = 2010;
_328i.year = 2019;
gallardo.year = 2020;
corniche.year = 1998;
How does one build an array of the var values for the property maker
Something that might console log like this:
(5) ['VW', 'Nissan', 'BMW', 'Lamborghini', 'Roll Royce']
You could create an array of the car instances and use the map function
console.log(
[golf, sentra, _328i, gallardo, corniche].map((car) => car.maker)
)
There are a lot of solutions to that. First, you need to make an array with all your cars, and then use a method to iterate on each car to get the car maker.
Here two examples:
var Car = function (maker, type, model) {
this.maker = maker;
this.type = type;
this.model = model;
}
Car.prototype.year = 0;
var golf = new Car ('VW', 'Hatchback', 'Golf');
var sentra = new Car ('Nissan', 'Sedan', 'Sentra');
var _328i = new Car ('BMW', 'Convertible', "328i");
var gallardo = new Car ('Lamborghini', 'Convertible', "Gallardo", 2020);
var corniche = new Car('Rolls Royce', 'Sedan', "Corniche");
golf.year = 2015;
sentra.year = 2010;
_328i.year = 2019;
gallardo.year = 2020;
corniche.year = 1998;
var cars = [golf, sentra, _328i, gallardo, corniche]
var carsMakers = []
for(var i = 0; i < cars.length; i++) {
var c = cars[i]
carsMakers.push(c.maker)
}
console.log(carsMakers)
var carsMakers2 = cars.map(function(c) { return c.maker });
console.log(carsMakers2)
Just like the map approach but using Array.prototype.from:
var Car = function (maker, type, model) {
this.maker = maker;
this.type = type;
this.model = model;
}
var golf = new Car ('VW', 'Hatchback', 'Golf');
var sentra = new Car ('Nissan', 'Sedan', 'Sentra');
var _328i = new Car ('BMW', 'Convertible', "328i");
var gallardo = new Car ('Lamborghini', 'Convertible', "Gallardo");
var corniche = new Car('Rolls Royce', 'Sedan', "Corniche");
Car.prototype.year = 0;
golf.year = 2015;
sentra.year = 2010;
_328i.year = 2019;
gallardo.year = 2020;
corniche.year = 1998;
// Solution here
const makersList = Array.from([golf, sentra, _328i, gallardo, corniche], car => car.maker );
// should print an array of makers string names
console.log(makersList);
Hi I have searched everywhere and although some questions and answers have helped I still cannot seem to get my array of objects to send to my PHP file (body_parts_submit.php).
Basically, I have created 6 arrays and within them they have objects its complicated but I want every body part, every exercise every set and rep and weight value to be different so I can distinguish between them later on.
The success function never seems to run when I run the code in a browser, so it could be the way I've structured the arrays or the javascript itself. Any help would be much appreciated I've been sitting on this problem for days.
$("#add-cart").click(function(){
var numBodyParts = parseInt($("input[name='number_bodypart']").val());
var bodyParts = new Array();
bodyParts[0] = "Body Parts:";
var exerciseNames = new Array();
exerciseNames[0] = new Array();
exerciseNames[0][0] = "Exercise names:";
var numOfSets = new Array();
numOfSets[0] = new Array();
numOfSets[0][0] = "Number of sets per exercise:";
var setNum = new Array();
setNum[0] = new Array();
setNum[0][0] = new Array();
setNum[0][0][0] = "Set Number:";
var repValue = new Array();
repValue[0] = new Array();
repValue[0][0] = new Array();
repValue[0][0][0] = "Number of reps:";
var weightValue = new Array();
weightValue[0] = new Array();
weightValue[0][0] = new Array();
weightValue[0][0][0] = "Amount of weight:";
for(b=1;b<=numBodyParts;b++){
bodyParts[b] = {bodypart:document.getElementById("bodypart_select"+b).value};
var numExercises = document.getElementById("table"+b).rows.length;
exerciseNames[b] = new Array();
numOfSets[b] = new Array();
setNum[b] = new Array();
repValue[b] = new Array();
weightValue[b] = new Array();
for(e = 1; e<=numExercises;e++){
exerciseNames[b][e] = {exercise:document.getElementById("exercise_"+b+"_"+e).value};
numOfSets[b][e] = {numofsets:document.getElementById("number_set_"+b+"_"+e).value};
var numofSets = document.getElementById("set_"+b+"_"+e).rows.length;
setNum[b][e] = new Array();
repValue[b][e] = new Array();
weightValue[b][e] = new Array();
for(s=1; s<=numofSets; s++){
setNum[b][e][s] = {setnum:s};
repValue[b][e][s] = {reps:document.getElementById(b+"_reps_"+e+"_"+s).value};
weightValue[b][e][s] = {weight:document.getElementById(b+"_weight_"+e+"_"+s).value};
}
}
}
var test1 = JSON.stringify(bodyParts[1]);
var test2 = JSON.stringify(exerciseNames);
var test3 = JSON.stringify(numOfSets);
var test4 = JSON.stringify(setNum);
var test5 = JSON.stringify(repValue[1][2][2]);
var test6 = JSON.stringify(weightValue[1][1][1]);
console.log(test1);
console.log(test2);
console.log(test3);
console.log(test4);
console.log(test5);
console.log(test6);
$.ajax({
type: "post",
url: "body_parts_submit.php",
data: {bodyparts:JSON.stringify(bodyParts[1])},
success: function(data){
alert("Success");
console.log(data);
},
error: function(e){
console.log(e.message);
},
dataType: "json"
});
});
Below is my php file - body_parts_submit.php
$data = json_decode($_POST["bodyparts"]);
if(isset($_POST["bodyparts"]))
{
$data = json_decode($_POST["bodyparts"]);
echo('{"reason": "'.$data.'"}');
}
else{
echo ('{"reason": "failure"}');
}
I'm running this program that makes a new array out of an old array of objects based on a few prompt questions. However when I run the program, if statement is not recognized in the for loop. The new array contains everything from the new array.
function verb(first,second,third,fourth,conjugation,chapter) {
this.first = first;
this.second = second;
this.third = third;
this.fourth = fourth;
this.conjugation = conjugation;
this.chapter = chapter;
}
// Now we can make an array of people
/*var family = new Array();
family[0] = new Person("alice", 40);
family[1] = new Person("bob", 42);
family[2] = new Person("michelle", 8);
// add the last family member, "timmy", who is 6 years old
family[3] = new Person("timmy", 6);*/
var family = new Array();
family[0] = new verb("amo","amare","amavi",'amatum',1,1);
family[1] = new verb("moneo","monere","monui","monitum",2,1);
family[2] = new verb("a "," a"," a","a ",3,6);
family[3] = new verb("debeo","debere","debui","debitum",2,1);
family[4] = new verb("do","dare","dedi","datum",1,1);
family[5] = new verb("servo","servare","servavi","servatum",1,1);
family[6] = new verb("conservo","conservare","conservavi","conservatum",1,1);
family[7] = new verb("terreo","terrere","terrui","territum",1,1);
family[8] = new verb("valeo","valere","valui","valitum",2,1);
family[9] = new verb("video","videre","vid","visum",2,1);
family[10] = new verb("voco","vocare","vocavi","vocatum",1,1);
family[11] = new verb("habeo","habere","habui","habitum",2,3);
family[12] = new verb("satio","satiare","satiavi","satiatum",1,3);
family[13] = new verb("culp","culpare","culpavi","culpatum",1,5);
family[14] = new verb(" ceno","cenare","cenavi","cenatum",1,5);
family[15] = new verb("maneo","manere","mansi","mansum",2,5);
family[16] = new verb("supero","supweare","superavi","superatum",1,5);
family[17] = new verb("tolero","tolerare","toleravi","toleratum",1,6);
family[18] = new verb("audeo","audere","ausus sum"," ",2,7);
family[19] = new verb("neco","necare","necavi","necatum",1,7);
family[20] = new verb("ago","agere","egi","actum",3,8);
var choose = prompt("do you want principle parts ?");
/*<?php echo $_POST["name"]; ?>
/*family[1] = new verb
family[2] = new verb
family[0].chapter
/*"var doceo = {
definition:"to teach",
first:"doceo",
second:"docere",
third:"dixi",
fourth:"doctum"
chapter:"3""*/
/*chap_beg = document.getElementById("0").submit;
chap_end = document.getElementByID("1").submit;*/
var chap_beg = prompt("What chapter do you want to begin?");
/*var chap_beg = <?php echo $_POST["name"]; ?>*/
var chap_end = prompt("what chapter do you want too end");
/* var chap_end = <?php echo $_POST["name"]; ?>*/
/*if((Math.random())*6<1){
person = 1;
}else if(1<(Math.random())*6<2){
person = 2;
}else if(2<(Math.random())*6<3){
person = 3;
}else if(3<(Math.random())*6<4){
person = 4;
}else if(4<(Math.random())*6<5){
person = 5;
}else if(5<(Math.random())*6<5){
person = 6;
} */
var helparray = new Array();
helparray[1]=1;
helparray[2]=2;
helparray[3]=3;
helparray[4]=4;
helparray[5]=5;
helparray[6]=6;
var person = helparray[Math.floor(Math.random() * helparray.length)];
var randselect = new Array();
for(i=0;i<family.length;i++) {
if( chap_beg < family[i].chapter < chap_end) {
console.log(family[i].first);
randselect.push(family[i]);
}else{
console.log("no");
}
/* console.log(randselect[randselect.length-1]);*/
}
var rand = randselect[Math.floor(Math.random() * (randselect.length - 1))];
/*var rand = randselect[Math.round(Math.random() * (randselect.length - 1))];*/`enter code here`
Yielding
amo
moneo
a
debeo
do
servo
conservo
terreo
valeo
video
voco
habeo
satio
culp
ceno
maneo
supero
tolero
audeo
neco
ago
This line...
if( chap_beg < family[i].chapter < chap_end) {
Should be
if( chap_beg < family[i].chapter && family[i].chapter < chap_end) {