- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到了 chartjs 的问题。我只是想要用饼图打印 div#browser
中的内容。图表很好,很生动,但问题是在我打印馅饼的过程中图表消失了,但当我再次刷新时,它就好了。这除饼图外,其他图表在打印时效果很好。我相信它的原因是在动画什么的
chartjs 脚本
<script>
var pieChartCanvas = $("#pieChart").get(0).getContext("2d");
var pieChart = new Chart(pieChartCanvas);
var PieData = [
{
value: 700,
color: "#f56954",
highlight: "
#f56954",
label: "Chrome"
},
{
value: 500,
color: "#00a65a",
highlight: "#00a65a",
label: "IE"
},
{
value: 400,
color: "#f39c12",
highlight: "#f39c12",
label: "FireFox"
},
{
value: 600,
color: "#00c0ef",
highlight: "#00c0ef",
label: "Safari"
},
{
value: 300,
color: "#3c8dbc",
highlight: "#3c8dbc",
label: "Opera"
},
{
value: 100,
color: "#d2d6de",
highlight: "#d2d6de",
label: "Navigator"
}
];
var pieOptions = {
//Boolean - Whether we should show a stroke on each segment
segmentShowStroke: true,
//String - The colour of each segment stroke
segmentStrokeColor: "#fff",
//Number - The width of each segment stroke
segmentStrokeWidth: 1,
//Number - The percentage of the chart that we cut out of the middle
percentageInnerCutout: 50, // This is 0 for Pie charts
//Number - Amount of animation steps
animationSteps: 100,
//String - Animation easing effect
animationEasing: "easeOutBounce",
//Boolean - Whether we animate the rotation of the Doughnut
animateRotate: true,
//Boolean - Whether we animate scaling the Doughnut from the centre
animateScale: false,
//Boolean - whether to make the chart responsive to window resizing
responsive: true,
// Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
maintainAspectRatio: false,
//String - A legend template
legendTemplate: "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>",
//String - A tooltip template
tooltipTemplate: "<%=value %> <%=label%> users"
};
//Create pie or douhnut chart
// You can switch between pie and douhnut using the method below.
pieChart.Doughnut(PieData, pieOptions);
</script>
html
<div id="browser">
<h3 class="box-title">Browser Usage</h3>
<a onclick="printContent('browser')">Print</a>
<div class="chart-responsive">
<canvas id="pieChart" height="150"></canvas>
</div>
</div>
打印脚本
<script>
function printContent(el){
var restorepage = document.body.innerHTML;
var printcontent = document.getElementById(el).innerHTML;
document.body.innerHTML = printcontent;
window.print();
document.body.innerHTML = restorepage;
}
</script>
最佳答案
尝试使用 .toDataURL()
Canvas 上的方法。此方法返回包含您的图表作为图像的 URL。 https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL
捕获饼图的 Canvas 并将其转换为图像:document.getElementbyId('pieChart').toDataURL;
将生成的图表图片URL赋给一个变量,让我们继续使用printContents
在这种情况下:let **printContents** = document.getElementbyId('pieChart').toDataURL;
动态启动 html 文档并将之前创建的图像 URL 附加为 <img>
元素的来源,使用 template literals
嵌入 printContents 变量:让 html = <html><head><title></title></head><body><img src=${printContent}></body></html>
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
-通过将先前构建的html文档动态写入打印窗口来执行打印作业(Chrome):
let **printWindow** = window.open('', 'Print-Preview', 'height=900,width=200');
printWindow.document.open();
printwindow.document.write(html);
printWindow.document.close();
关于javascript - 在chartjs中打印饼图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39864143/
有没有办法在 vue-chartjs 中制作带圆角的条形图?我在谷歌上搜索了一下,发现我们可以使用此 url 中给出的渲染条的实现来扩展条形图 - How to put rounded corners
我想通过提供两个数组来创建多条垂直线,第一个称为marketing,其中包含诸如“2017-09-21”等日期和一个数组称为 amount,仅包含数字。 我使用 ChartJS 创建了折线图。最终结果
(对不起我的英语)我将 chartjs-plugin-streaming 用于实时 chartjs,我想使用 chartjs-plugin-zoom。 但是缩放不起作用。 当我测试缩放时,出现缩放区域
我使用 angualr2-chartjs 来显示图表。我的问题是当我动态更改选项时图表更新只有一次。在控制台中,我看到一切都很好,但在 View 中我看不到变化。我使用了 chartjs-plugin
我正在尝试创建类似于 www.chartjs.org 顶部的内容其中有一个随机移动的背景条形图。我发现了另一个类似的question ,但是它似乎不起作用。当我在下面添加时,它不会添加除 400x40
感谢任何提示和/或帮助!我在这里碰壁试图让图表呈现。我已经恢复到测试一个非常简单的方法(下面的代码),但我仍然收到以下错误: 类型错误:无法读取未定义的属性(读取“ map ”) 我可以记录从 use
chartjs-plugin-zoom是 Chart.js 的缩放和平移插件 您可以调用 chart.resetZoom() 以编程方式将缩放重置为默认状态。参见 this example on js
我正在尝试将 Chart.js 与 Vue.js 一起使用,这就是我得到的编译结果,但我没有在 GUI 上看到任何显示。 这是我的文件 DonutChart.vue: // NOT SURE IF
好的,所以我正在尝试通过 VueJS 创建一个 ChartJS 实例,以便我可以通过组件内的 AJAX 请求轻松更新其数据。 基本上它可以工作,创建了 ChartJS 实例,但它是空的,高度和宽度为
我想从 chartjs-chart-treemap 添加树状图到我现有的使用 react-chartjs-2 的项目中. 我到目前为止尝试过: import ChartComponent from '
是否可以定义具有多级别/类别轴的条形图? 例如,我想显示地区/省类别,如下 Excel 图表所示: 我找到了this使用多个 xAxes 的示例。 xAxes:[ { id:'xA
我正在使用 chart.js (V2) 尝试构建一个条形图,用户无需将鼠标悬停在任何地方或点击任何地方即可获得更多信息。我提供了两个示例,说明我希望如何编辑我的图表。 Two edited versi
我想使用 Chartjs(chartjs.org) 作为我的图表工具以及使用 TypeScript 的 AngularJS。我已经从 GitHub 安装了 DefinitelyTyped for Ch
我正在使用 chartjs-plugin-datalabels,并且在大图表中显示较小的数据集时值重叠 这是 chartjs-data-plugin 配置 options: { plu
var yLabels = { 1 : 'New', 2 : 'Learning Phase', 3
我正在创建图表以使用图表 js 呈现一些数据。 const data = { labels: ["1 Dec", "8 Dec", "16 Dec", "31 Dec"], dat
我正在尝试将其他数据插入圆环图中。 Controller 将这样的数组传递给 View : [ 0 => array:3 [ "profit" => 20 "sex" => arr
将百分比值添加到图例标签的最简单方法是什么? 我相信它会使用 generateLabels: function (chart) {},谁能提供一个干净的例子? 最佳答案 似乎没有任何本地方式来显示百分
我已经多次看到这个问题,但我找不到适合我的解决方案。 我将一个 Django 变量传递给 Chartjs 进行绘图,所有的个位数都是正确的,但它将两位数变成了一个。像 11 是 1,1...23 是
我正在尝试使用 chartjs 数据标签插件获取每个条上的值。 所以在条形“a”上方 a 想看到数字 30 及以上或在条形“b”内我想看到数字 50。 但它根本没有显示任何值。 任何人都可以帮助并告诉
我是一名优秀的程序员,十分优秀!