- Home
- Forum
- ASP.NET MVC
- How to excel export the chart of more than one category.
How to excel export the chart of more than one category.
Hi,
I'm very grateful to you.
I'm currently implementing the excel export function of the chart.
but, I don't know how to excel export the chart of more than one category.
What should I do?
Framework: ASP.NET MVC5
* View
<button onclick="download()">download</button> <div id="chart"></div> <script> $(function ($) { init(); }); function init() { $("#chart").ejChart({ series: [ { name: "category1", points: [ { x: 1, y: 2 }, { x: 2, y: 5 } ], xName: "X", yName: "Y" }, { name: "category2", points: [ { x: 1, y: 3 }, { x: 2, y: 6 } ], xName: "X", yName: "Y" } ] }); } function download() { var chart = $("#chart").ejChart("instance"); chart.model.exportSettings.fileName = "Chart"; chart.model.exportSettings.orientation = "portrait"; chart.model.exportSettings.action = "/Home/ExportChart"; chart.model.exportSettings.type = "xlsx"; chart.model.exportSettings.mode = "server"; chart.model.exportSettings.multipleExport = false; chart.export(); return true; } </script> |
* Controller
public void ExportChart(string Data, string ChartModel) { ChartProperties obj = ConvertChartObject(ChartModel); string type = obj.ExportSettings.Type.ToString().ToLower(); string fileName = obj.ExportSettings.FileName; string orientation = obj.ExportSettings.Orientation.ToString(); List<ExportChartData> chartData = new List<ExportChartData>(); ExcelExport exp = new ExcelExport(); exp.Export(obj, chartData, fileName + ".xlsx", ExcelVersion.Excel2010, null, null); } public class ExportChartData { public ExportChartData(string x, string y) { this.X = x; this.Y = y; } public string X { get; set; } public string Y { get; set; } } |
* Export Chart Example
SIGN IN To post a reply.
3 Replies
AT
Anandaraj T
Syncfusion Team
November 11, 2016 01:17 PM UTC
Hi Yuta,
Thanks for using Syncfusion products.
We have created a sample with the code snippet provided by you, it works fine for exporting multiple series (category). The sample can be downloaded from the following link
Note:
1) Excel version (or higher) provided in export action method should be present in the client machine to open the excel worksheet. In your code snippet, Excel 2010 version is specified.
2) Excel exporting does not depend upon the number of series (category) or data points. The same code (ExportChart method) can be used for exporting charts with different configurations to excel worksheet.
Chart in exported excel file
Could you please let us know the version of Essential Studio you are using ? We will let you know if there are any changes to the above code in specified version.
Please let us know if you have any concern.
Regards,
Anand
YU
Yuta
November 12, 2016 02:02 PM UTC
Hello,
Thank you for the advice and sample.
I was misunderstanding.
I was emptying "chartData" for inquiries (whitout "chartData.Add(..)") , but in fact it was unnecessary.
When I ran it as it was, it was the expected behavior.
Thank you very much.
AB
Akbar Basha K M
Syncfusion Team
November 14, 2016 11:55 AM UTC
Hi Yuta,
Most Welcome. Please let us know if you need any further assistance on this.
Thanks,
Akbar Basha KM.
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
YU Yuta
- Nov 10, 2016 08:44 AM UTC
- Nov 14, 2016 11:55 AM UTC