热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何将JavaScript图表导出到Excel文件(HighCharts)-HowtoExportJavaScriptCharttoExcelfile(HighCharts)

IhavetoExportaJavascriptchart(HighCharts)intoanexcelfile;thechartwasrenderedinadiv

I have to Export a Javascript chart (HighCharts) into an excel file; the chart was rendered in a div, but the excel doesn't render the html+css content the Javascript generates, render only the text without style.

我必须将Javascript图表(HighCharts)导出到excel文件中;图表是在div中呈现的,但是excel不呈现Javascript生成的html+css内容,只呈现没有样式的文本。

A solution would be convert this where the chart was rendered into an image(jpeg) but I have no success...

一个解决方案是将这个图转换成一个图像(jpeg),但是我没有成功……

Thanks !

谢谢!

5 个解决方案

#1


2  

HighCharts already supports the image exporting functionality via the Exporting Module which is packaged with it. Exporting After getting it you should be able to modify the script to save the image in any way you need. It's certainly not a beginners task and will require lots of tinkering.

HighCharts已经通过与之打包的导出模块支持图像导出功能。导出之后,您应该能够修改脚本,以以任何您需要的方式保存映像。这当然不是一个初学者的任务,需要大量的修补工作。

If it were me I would modify the code that responds to the export button so that I can activate it with Javascript and also pass in information so that the PHP file on the back-end could save the picture in the manner you want rather than returning it to the client.

如果是我,我将修改代码来响应导出按钮,这样我也可以用Javascript和激活它传递信息,以便后端上的PHP文件可以保存图片你想要的方式而不是返回给客户端。

#2


1  

This might be a little late, but I stumbled across this via Google so it might help someone. Highchart's image is in SVG format: http://en.wikipedia.org/wiki/Svg , you need to convert that to a bitmap format image. You have to change the Highcharts exporting options URL to your own URL:

这可能有点晚了,但我是通过谷歌偶然发现的,所以它可能会帮助某些人。Highchart的图像是SVG格式:http://en.wikipedia.org/wiki/Svg,需要将其转换为位图格式的图像。您必须将Highcharts导出选项URL更改为您自己的URL:

exporting : {
  url: 'http://mydomain.com/export.php'
}

In your export script you must convert the SVG image to a bitmap image (I used PHP & imagick) then export to whatever suits your needs, save the bitmap image to the server, send by e-mail, etc. ,

在导出脚本中,您必须将SVG图像转换为位图图像(我使用了PHP和imagick),然后导出任何适合您需要的内容,将位图图像保存到服务器,通过电子邮件发送,等等。

#3


1  

After some searching, I found this recent answer in their forums, with a jsfiddle to tinker with.

在搜索之后,我在他们的论坛上找到了这个最近的答案,我需要修改一下。

It describes how to export a CSV using a script on your server, which from past experience, is the only way this can get done because the HighChart graph itself doesn't contain nearly enough information to produce a usable spreadsheet. We already do with a different charting library, and use phpExcel to actually create the spreadsheet.

它描述了如何使用服务器上的脚本导出CSV,这是过去经验中惟一可以实现的方法,因为HighChart图本身没有包含足够的信息来生成可用的电子表格。我们已经使用了不同的绘图库,并使用phpExcel实际创建电子表格。

#4


1  

If you are willing to try an Add-in, there is a way to use Javascript, HTML and css in Excel. It's called Funfun and it hosts an online editor with an embedded spreadsheet so the transition isn't hard between the website to Excel.

如果您愿意尝试外接程序,那么在Excel中有一种使用Javascript、HTML和css的方法。它叫做Funfun,它有一个在线编辑器,里面有一个嵌入式的电子表格,所以在网站之间转换成Excel并不难。

Here is a chart I made with Highcharts:

这是我用海图制作的一张图表:

https://www.funfun.io/1/#/edit/5a61c190404f66229bda3f0f

https://www.funfun.io/1/ /编辑/ 5 a61c190404f66229bda3f0f

In this example I took the chart from a Highchart demo, and replaced the data with mine. I store my data in the embedded spreadsheet, and thanks to a json file I can use it in my Javascript code.

在这个示例中,我从一个Highchart演示中获取图表,并将数据替换为我的。我将数据存储在嵌入式电子表格中,由于有了json文件,我可以在Javascript代码中使用它。

That is how I get my data from the spreadsheet with the json file:

这就是我从json文件的电子表格中获取数据的方式:

{
    "data": "=A1:E16"
}

I store it in my script.js with the right format so I can directly load it in Highcharts (for numbers you must convert your data into floats or int):

我将它保存在我的脚本中。使用正确的格式,这样我就可以直接以海图的形式加载它(对于数字,您必须将数据转换为浮点数或int):

var data = [];

for (var i = 1; i <$internal.data.length; i++)
  data.push(
    {
      x: parseFloat($internal.data[i][2]),
      y: parseFloat($internal.data[i][3]),
      z: parseFloat($internal.data[i][4]),
      name: $internal.data[i][1],
      country: $internal.data[i][0]
    }
  );

After You've chosen all of you're options for your chart you can add your data:

在您选择了所有的图表选项后,您可以添加您的数据:

series: [{
        data: data
    }]

Once you are happy with your chart you can directly load it into Excel by pasting the URL in the Funfun add-in. Here is how it looks like with my example:

一旦你对你的图表满意,你可以直接将它加载到Excel中,粘贴在Funfun插件中的URL。下面是我的例子:

final

Of course you can use another library than Highcharts, there are a lot of powerful libraries for data visualization like charts.js and D3.js.

当然,除了Highcharts之外,您还可以使用其他库,有很多强大的库用于数据可视化,比如charts。js和D3.js。

I know this is an old post but I hope it helps people with the same problem.

我知道这是一个古老的帖子,但我希望它能帮助人们解决同样的问题。

Disclosure : I’m a developer of Funfun.

我是Funfun的开发者。

#5


0  

I know it's too late but i have the same problem and this jsfiddle helped me to create excel from highchart. The Download CSV option added to export menu works fine. Here is the code:

我知道已经太晚了,但是我有同样的问题,这个jsfiddle帮助我从highchart创建excel。添加到导出菜单的下载CSV选项可以正常工作。这是代码:

/**
 * A small plugin for getting the CSV of a categorized chart
 */
(function (Highcharts) {

    // Options
    var itemDelimiter = ',',  // use ';' for direct import to Excel
        lineDelimiter = '\n';

    var each = Highcharts.each;
    Highcharts.Chart.prototype.getCSV = function () {
        var xAxis = this.xAxis[0],
            columns = [],
            line,
            csv = "", 
            row,
            col;

        if (xAxis.categories) {
            columns.push(xAxis.categories);
            columns[0].unshift("");
        }
        each (this.series, function (series) {
            columns.push(series.yData);
            columns[columns.length - 1].unshift(series.name);
        });

        // Transform the columns to CSV
        for (row = 0; row 

推荐阅读
  • 主调|大侠_重温C++ ... [详细]
  • 本文介绍如何使用Objective-C结合dispatch库进行并发编程,以提高素数计数任务的效率。通过对比纯C代码与引入并发机制后的代码,展示dispatch库的强大功能。 ... [详细]
  • 导航栏样式练习:项目实例解析
    本文详细介绍了如何创建一个具有动态效果的导航栏,包括HTML、CSS和JavaScript代码的实现,并附有详细的说明和效果图。 ... [详细]
  • 主要用了2个类来实现的,话不多说,直接看运行结果,然后在奉上源代码1.Index.javaimportjava.awt.Color;im ... [详细]
  • 前言--页数多了以后需要指定到某一页(只做了功能,样式没有细调)html ... [详细]
  • UNP 第9章:主机名与地址转换
    本章探讨了用于在主机名和数值地址之间进行转换的函数,如gethostbyname和gethostbyaddr。此外,还介绍了getservbyname和getservbyport函数,用于在服务器名和端口号之间进行转换。 ... [详细]
  • JavaScript中属性节点的类型及应用
    本文深入探讨了JavaScript中属性节点的不同类型及其在实际开发中的应用,帮助开发者更好地理解和处理HTML元素的属性。通过具体的案例和代码示例,我们将详细解析如何操作这些属性节点。 ... [详细]
  • 本文详细介绍了如何在ECharts中使用线性渐变色,通过echarts.graphic.LinearGradient方法实现。文章不仅提供了完整的代码示例,还解释了各个参数的具体含义及其应用场景。 ... [详细]
  • JavaScript 基础语法指南
    本文详细介绍了 JavaScript 的基础语法,包括变量、数据类型、运算符、语句和函数等内容,旨在为初学者提供全面的入门指导。 ... [详细]
  • This request pertains to exporting the hosted_zone_id attribute associated with the aws_rds_cluster resource in Terraform configurations. The absence of this attribute can lead to issues when integrating DNS records with Route 53. ... [详细]
  • 简化报表生成:EasyReport工具的全面解析
    本文详细介绍了EasyReport,一个易于使用的开源Web报表工具。该工具支持Hadoop、HBase及多种关系型数据库,能够将SQL查询结果转换为HTML表格,并提供Excel导出、图表显示和表头冻结等功能。 ... [详细]
  • 深入理解Vue.js:从入门到精通
    本文详细介绍了Vue.js的基础知识、安装方法、核心概念及实战案例,帮助开发者全面掌握这一流行的前端框架。 ... [详细]
  • 深入解析 Android IPC 中的 Messenger 机制
    本文详细介绍了 Android 中基于消息传递的进程间通信(IPC)机制——Messenger。通过实例和源码分析,帮助开发者更好地理解和使用这一高效的通信工具。 ... [详细]
  • 题目Link题目学习link1题目学习link2题目学习link3%%%受益匪浅!-----&# ... [详细]
  • SQLite 动态创建多个表的需求在网络上有不少讨论,但很少有详细的解决方案。本文将介绍如何在 Qt 环境中使用 QString 类轻松实现 SQLite 表的动态创建,并提供详细的步骤和示例代码。 ... [详细]
author-avatar
自由战狼2012
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有