热门标签 | 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 

推荐阅读
  • Java如何导入和导出Excel文件的方法和步骤详解
    本文详细介绍了在SpringBoot中使用Java导入和导出Excel文件的方法和步骤,包括添加操作Excel的依赖、自定义注解等。文章还提供了示例代码,并将代码上传至GitHub供访问。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • 导出功能protectedvoidbtnExport(objectsender,EventArgse){用来打开下载窗口stringfileName中 ... [详细]
  • MATLAB函数重名问题解决方法及数据导入导出操作详解
    本文介绍了解决MATLAB函数重名的方法,并详细讲解了数据导入和导出的操作。包括使用菜单导入数据、在工作区直接新建变量、粘贴数据到.m文件或.txt文件并用load命令调用、使用save命令导出数据等方法。同时还介绍了使用dlmread函数调用数据的方法。通过本文的内容,读者可以更好地处理MATLAB中的函数重名问题,并掌握数据导入导出的各种操作。 ... [详细]
  • Javascript中带有加号 - 减号(±)的极坐标曲线方程 - Polar curve equation with plus-minus sign (±) in Javascript
    IamtryingtodrawpolarcurvesonHTMLcanvasusingJavascript.WhatshouldIdowhenIwanttoco ... [详细]
  • 本文介绍了一个免费的asp.net控件,该控件具备数据显示、录入、更新、删除等功能。它比datagrid更易用、更实用,同时具备多种功能,例如属性设置、数据排序、字段类型格式化显示、密码字段支持、图像字段上传和生成缩略图等。此外,它还提供了数据验证、日期选择器、数字选择器等功能,以及防止注入攻击、非本页提交和自动分页技术等安全性和性能优化功能。最后,该控件还支持字段值合计和数据导出功能。总之,该控件功能强大且免费,适用于asp.net开发。 ... [详细]
  • java drools5_Java Drools5.1 规则流基础【示例】(中)
    五、规则文件及规则流EduInfoRule.drl:packagemyrules;importsample.Employ;ruleBachelorruleflow-group ... [详细]
  • node.jsrequire和ES6导入导出的区别原 ... [详细]
  • PHP反射API的功能和用途详解
    本文详细介绍了PHP反射API的功能和用途,包括动态获取信息和调用对象方法的功能,以及自动加载插件、生成文档、扩充PHP语言等用途。通过反射API,可以获取类的元数据,创建类的实例,调用方法,传递参数,动态调用类的静态方法等。PHP反射API是一种内建的OOP技术扩展,通过使用Reflection、ReflectionClass和ReflectionMethod等类,可以帮助我们分析其他类、接口、方法、属性和扩展。 ... [详细]
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社区 版权所有