// if there is no printing section, create one
if (!printSection) {
printSection = document.createElement('div');
printSection.id = 'printSection';
document.body.appendChild(printSection);
}
function link(scope, element, attrs) {
element.on('click', function () {
var elemToPrint = document.getElementById(attrs.printElementId);
if (elemToPrint) {
printElement(elemToPrint);
// tried to resize chart with chart.setSize() and it works here
window.print();
}
});
window.onafterprint = function () {
// clean the print section before adding new content
// when I tried to resize the chart back to normal size, it doesn't work
}
}
function printElement(elem) {
// clones the element you want to print
var domClone = elem.cloneNode(true);
printSection.appendChild(domClone);
}
return {
link: link,
restrict: 'A'
};
< /code>
ниже используется CSS: < /p>
@media screen {
#printSection {
display: none;
}
}
@media print {
body * {
visibility:hidden;
}
#printSection, #printSection * {
visibility:visible;
}
#printSection {
position:absolute;
left:0;
top:0;
}
}
< /code>
Помимо диаграммы, все напечатано правильно на странице. Диаграмма обрезается при печати. Как я знаю, Hightchart отзывчив, но он не работает должным образом в макете печати. На последующих вызовах печати новый элемент диаграммы добавляется в Dom. < /P>
[b] Чего мне здесь не хватает? Нужно ли изменить размер диаграммы или перекрасить? А где его изменить или перерисовать? Нужно ли применить CSS
HighThart интегрирован в Directive AngularJS . Директива только печатает содержание элемента. Ниже приведен Кодекс Директивы. Взял код отсюда < /p> [code]// if there is no printing section, create one if (!printSection) { printSection = document.createElement('div'); printSection.id = 'printSection'; document.body.appendChild(printSection); }
function link(scope, element, attrs) { element.on('click', function () { var elemToPrint = document.getElementById(attrs.printElementId); if (elemToPrint) { printElement(elemToPrint); // tried to resize chart with chart.setSize() and it works here window.print(); } });
window.onafterprint = function () { // clean the print section before adding new content // when I tried to resize the chart back to normal size, it doesn't work } }
function printElement(elem) { // clones the element you want to print var domClone = elem.cloneNode(true); printSection.appendChild(domClone); }
@media print { body * { visibility:hidden; } #printSection, #printSection * { visibility:visible; } #printSection { position:absolute; left:0; top:0; } } < /code> Помимо диаграммы, все напечатано правильно на странице. Диаграмма обрезается при печати. Как я знаю, Hightchart отзывчив, но он не работает должным образом в макете печати. На последующих вызовах печати новый элемент диаграммы добавляется в Dom. < /P> [b] Чего мне здесь не хватает? Нужно ли изменить размер диаграммы или перекрасить? А где его изменить или перерисовать? Нужно ли применить CSS [/code] к элементу HighChart? [/b]