Line chart not displaying correctly within modal box - html

I am new to HTML jquery. I'm stuck on the below issue and unsure not sure how to go about solving it.
I have added a line chart onto a modal box. The chart displays, but only at half the height of the modal height, when I would have expected the entire modal height to be used.
My HTML code is follows
<div id = "myModal" class="modal">
<div class="modalContent">
<span class = "close"> </span>
<div id="data_chart"></div>
</div>
</div>
The jquery function I use to create the chart is below, I left out some formatting codes for simplicity.
function renderChart() {
//===========================
var len = data_obj["trend"]["x"].length;
var trend_data = []
for (var i=0; i<len; i++){
var d = new Date(data_obj["trend"]["x"][i]);
var t = {"date": d, "value": data_obj["trend"]["y"][i]};
trend_data.push(t)};
var chart = am4core.create("data_chart", am4charts.XYChart);
chart.data=trend_data;
var title = chart.titles.create();
title.text = "Pulse Index";
title.marginBottom = 30;
title.fontSize = 16;
var dateAxis_line = chart.xAxes.push(new am4charts.DateAxis());
dateAxis_line.renderer.inside = true;
dateAxis_line.renderer.grid.template.disabled = true;
// Create value axis
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
};
The output of the modal & chart shows the chart's height is not fully occupying the height of the modal box. I am not sure why.
For more detail, the DOM details are
Many thanks!

Related

How do you center text horizontally inside cells when inputting a template in docs?

Here's what I have:
function onOpen() {
DocumentApp.getUi()
.createMenu('New Table')
.addItem('Add Table', 'addTable')
.addToUi();
}
function addTable() {
var body = DocumentApp.getActiveDocument().getBody();
// body.insertHorizontalRule(1);
// var center = body.insertParagraph(1, ' ');
// center.setAlignment(DocumentApp.HorizontalAlignment.CENTER);
var cells = [
['', 'Lunch','Dinner'],
['SALES', ' ',''],
['MEALS', ' ',''],
['IDEAL STAFFING LEVELS'],
['Senior','',''],
['Junior','',''],
['Host','',''],
['Kitchen','',''],
['Dish','',''],
['Service','',''],
['Expo','',''],
['Skip','',''],
['Super','',''],
[' '],
['Weather','',''],
['Events','',''],
['Other','',''],
['Day Manager:',''],
['Log:',''],
['Night Manager',''],
['Log',''],
];
var table1 = body.insertTable(2,cells);
table1.setColumnWidth(0, 125);
table1.setColumnWidth(1, 100);
table1.setColumnWidth(2, 100);
var style = {};
// style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] =
// DocumentApp.HorizontalAlignment.CENTER;
//style[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri';
style[DocumentApp.Attribute.FONT_SIZE] = 7;
//style.table1.setVerticalAlignment(DocumentApp.VerticalAlignment.CENTER)
//style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.CENTER;
table1.setAttributes(style);
// var alignment = {};
// alignment[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] =
// DocumentApp.HorizontalAlignment.CENTER;
// //alignment.setAlignment(DocumentApp.HorizontalAlignment.CENTER);
// table1.setAttributes(alignment);
var tableHeader = table1.getRow(0);
var headerStyle = {};
//headerStyle[DocumentApp.Attribute.BACKGROUND_COLOR] = '#C0C0C0';
headerStyle[DocumentApp.Attribute.BOLD] = true;
tableHeader.setAttributes(headerStyle);
var tableBold1 = table1.getRow(1);
var boldStyle = {};
boldStyle[DocumentApp.Attribute.BOLD] = true;
tableBold1.setAttributes(boldStyle);
var tableBold2 = table1.getRow(2);
var boldStyle = {};
boldStyle[DocumentApp.Attribute.BOLD] = true;
tableBold2.setAttributes(boldStyle);
var tableBold3 = table1.getRow(3);
var boldStyle = {};
boldStyle[DocumentApp.Attribute.BOLD] = true;
tableBold3.setAttributes(boldStyle);
}
Tried a variety of ways I have come across as seen in my notes but I am new to this and only starting to understand the smallest bits. I've read something about maybe needing to use insertParagraph here: How to insert and center text in Google Docs with script but am unable to figure out the correct format for that to work in this circumstance.
I would also like to be able to return the font size to normal after the table. What is the proper function for that?
Any help is greatly appreciated!
Thanks in advance
thisisnotadupp
This appears to be a bug!
I have taken the liberty of reporting this on Google's Issue Tracker for you, detailing the behaviour:
Horizontal and Vertical alignment not being respected programmatically in table cells in Google Docs
You can hit the ☆ next to the issue number in the top left on the page which lets Google know more people are encountering this and so it is more likely to be seen to faster.

Add image as an attribute value in popover(solved)

I am trying to show an image in the popover,
after i created an element i add attributes to show an popover.
var item = document.createElement('div');
var att2 = document.createAttribute("data-toggle");
var att3 = document.createAttribute("title");
var att4 = document.createAttribute("data-content");
var att5 = document.createAttribute("data-placement");
att4.value = "<img src ='blablabla.png' />;"
att3.value = itemname;
att2.value = "popover";
att5.value = "top"
item.setAttributeNode(att5);
item.setAttributeNode(att2);
item.setAttributeNode(att3);
item.setAttributeNode(att4);
any idea ? the output in the popover content is <img src ='blablabla.png' />;
SOLUTION
just add html:true into
$('[data-toggle="popover"]').popover({html:true,trigger:"hover",container: 'body'});
function addImg(theDiv,theImg) {
var element = document.createElement("img");
element.src = theImg;
document.getElementById(theDiv).appendChild(element);
}
<div id="myDiv" onclick="addImg('myDiv','https://media1.popsugar-assets.com/files/thumbor/7NnYpYvDfxr_HYUpa4tySashCM8/fit-in/1024x1024/filters:format_auto-!!-:strip_icc-!!-/2017/03/17/915/n/1922398/40d6ad1840bc51bf_GettyImages-89938282/i/1997.jpg')">
Click me to append image
</div>
Is this kinda what you're after? Hard to tell from your explanation.

HTML Div not Showing

I have a query: My HTML code shows some SVG gauge(taken from google-chartdiv), I want to display it twice on my page but it appears on first time and after that no matter how many I place in HTML code it does not show. How to display it for multiple times in one HTML page. Please advise.
<div class="col-md-3">
<div class="row no-gutter">
<div class="col-md-12 gage">
<h1>Avg Handle Time (Sec)</h1>
<div id="chartdiv" style="width:350px; height:300px;"></div>
<span>#ViewBag.Name</span>
</div>
<div class="col-md-6">
<div class="row no-gutter">
<div class="col-md-12 gage">
<h1>Service Level %</h1>
<div id="chartdiv" style="width:350px; height:300px;"></div>
<span>#ViewBag.Age</span>
</div>
My chartdiv code is:
<script>
var chart;
var arrow;
var axis;
AmCharts.ready(function () {
// create angular gauge
chart = new AmCharts.AmAngularGauge();
chart.addTitle("Speedometer");
// In gauge.js has Nailradius , set the circular bottom of needle from there
// create axis
axis = new AmCharts.GaugeAxis();
axis.startValue = 0;
axis.axisThickness = 5;
axis.valueInterval = 50;
axis.endValue = 300;
// color bands
var band1 = new AmCharts.GaugeBand();
band1.startValue = 0;
band1.endValue = 180;
band1.innerRadius = "94%"; // The thickness of Color Scheme lesser % = thick color
band1.color = "#00CC00";
var band2 = new AmCharts.GaugeBand();
band2.startValue = 180;
band2.endValue = 240;
band2.color = "#ffac29";
band2.innerRadius = "94%"; // The thickness of Color Scheme lesser % = thick color
var band3 = new AmCharts.GaugeBand();
band3.startValue = 240;
band3.endValue = 300;
band3.color = "#ea3838";
band3.innerRadius = "94%"; // The thickness of Color Scheme lesser % = thick color
axis.bands = [band1, band2, band3];
// bottom text
axis.bottomTextYOffset = -20;
axis.setBottomText("0 km/h");
chart.addAxis(axis);
// gauge arrow
arrow = new AmCharts.GaugeArrow();
arrow.color = "#0000"; // Arrow color set to Black
arrow.startWidth = "10"; //This is the width of Arrow connection with Base Circle
arrow.radius = "100"; // This is the area covered by needle during motion
chart.addArrow(arrow);
chart.write("chartdiv1");
// change value every 2 seconds
setInterval(randomValue, 2000);
});
// set random value
function randomValue() {
var value = Math.round(Math.random() * 200);
arrow.setValue(value);
axis.setBottomText(value + " km/h");
}
</script>
The Problem was with the CSS scripts referred in HTML file. I was giving wrong Paths of CSS file having my SVG gauge. One path was correct while other was not pointing Correct.

Is dynamic div loading taking more time than static div in HTML?

In my application, a large number of divs is dynamically rendered in an HTML page through the use of JavaScript. In fact, there are more than 100 dynamically created divs. Loading the content from server side, it is taking more time to load dynamic divs than static divs. How can I reduce the time it takes to load dynamic divs? This is the sample code I am using:
var ul_slide = document.createElement('ul');
var slide_div = document.createElement('div');
slide_div.setAttribute("class", "slide");
for (var i = 0; i < data.arrayItems.length; i++) {
alert(data.arrayItems.length);
var postId = data.arrayItems[i].postId;
var tag = data.arrayItems[i].tag;
var li_slide1 = document.createElement('li');
var img_link1 = document.createElement('a');
var linka = "#" + postId;
img_link1.setAttribute("href", linka);
img_link1.setAttribute("class", "click");
var img_slide1 = new Image();
img_slide1.style.width = "159px";
img_slide1.style.height = "100px";
img_slide1.setAttribute("src",data.arrayItems[i].url);
img_link1.appendChild(img_slide1);
li_slide1.appendChild(img_link1);
ul_slide.appendChild(li_slide1);
slide_div.appendChild(ul_slide);
div.innerHTML = "";
div.appendChild(slide_div);
}

Displaying PopupPanel

THREE QUESTIONS:
Why does my popupPanel not display correctly?
How can I only get it to appear once if clicked multiple times?
How can I add a Close button to the popupPanel?
function showPassword(e){
var app = UiApp.getActiveApplication();
var vrtPanel = app.getElementById("vrtPanel");
//Create Spreadsheet Source
var spSheet = SpreadsheetApp.openById('0Aur3owCpuUY-dF92dGp3c2RORGNkY011dGFnMjBXbXc');
var spTeacherList = spSheet.getSheetByName('TeacherList');
//Create the form elements
var hdlTeacherName = app.createServerHandler('getTeacherName').addCallbackElement(vrtPanel);
var lbxTeacherName = app.createListBox().setId('lbxTeacherName').setName('lbxTeacherName').addChangeHandler(hdlTeacherName);
var lstTeacherNames = spTeacherList.getRange(1,1,spTeacherList.getLastRow(),1).getValues();
lstTeacherNames.sort();
for (var l = 0; l < lstTeacherNames.length; l++) {
lbxTeacherName.addItem(lstTeacherNames[l],l);
}
var lblTeacherName = app.createLabel('Teacher Name:');
var txtTeacherName = app.createTextBox().setName('txtTeacherName').setId('txtTeacherName').setVisible(false);
var lblExt = app.createLabel('Ext:');
var txtExt = app.createTextBox().setName('txtExt').setId('txtExt');
var lblEmail = app.createLabel('Email:');
var txtEmail = app.createTextBox().setName('txtEmail').setId('txtEmail');
var lblSchool = app.createLabel('School:');
var txtSchool = app.createTextBox().setName('txtSchool').setId('txtSchool');
var btnCreate = app.createButton('Create Event');
//Create validation handler
var valSubmit = app.createServerClickHandler('valSubmit');
valSubmit.addCallbackElement(vrtPanel);
//Add this handler to the button
btnCreate.addClickHandler(valSubmit);
//Add all the elemnts to the panel
var formTable = app.createFlexTable().setCellPadding(3);
vrtPanel.add(formTable);
formTable
.setWidget(0,0,lbxTeacherName)
.setWidget(0,1,txtExt)
.setWidget(0,2,txtTeacherName)
.setWidget(1,0,txtEmail)
.setWidget(2,0,btnCreate);
//Add all the panel to the popup
var popPassword = app.createDecoratedPopupPanel(false, true).setId("popPassword");
popPassword.add(vrtPanel);
app.add(vrtPanel);
app.add(popPassword);
return app;
}
There is some disorder in the way you use the popupPanel, you have to add it to your main panel and add the table you want to show in it to the popup itself.
You should also decide where you want to show it.
Here is the relevant part of your code working :
//Add all the elemnts to the panel
var formTable = app.createFlexTable().setCellPadding(3);
formTable
.setWidget(0,0,lbxTeacherName)
.setWidget(0,1,txtExt)
.setWidget(0,2,txtTeacherName)
.setWidget(1,0,txtEmail)
.setWidget(2,0,btnCreate);
var popPassword = app.createDecoratedPopupPanel(false, true).setPopupPosition(150,300).setId("popPassword");
vrtPanel.add(popPassword.add(formTable));
popPassword.show();
return app;
}
To answer the second point : il won't show up multiple time, just once.
point 3 : if you want to close it with a button you will have to add a button and a server handler to close it (by getting it with an ID just as any other widget) but it would be easier and userfriendly to take advantage of the autohide feature, just change the definition parameters like this :
var popPassword = app.createDecoratedPopupPanel(true).setPopupPosition(150,300).setId("popPassword");
edit : in the example above you can also use
app.getElementById('popPassword').hide()
in your 'valSubmit' function (called by the button) even without the autohide so the popup will hide when the handler function executes.