We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Chart export to excel

Hi,
V4.4.0.51 & VS2003

I want to export line chart with secondary YAxes to excel. I found the excel has custom type: "Lines on 2 Axes". How can I setup excel chart to this type in XslIO?

I know in excel VBA, I can use following code to set "Lines on 2 Axes". Do you have similar method in XslIO?

ActiveChart.ChartArea.Select
ActiveChart.PlotArea.Select
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:= _
"Lines on 2 Axes"

Thanks,


Lan

// A new workbook with 1 worksheet is created.
IWorkbook chartBook = ExcelUtils.CreateWorkbook(1);
// create chart worksheet
IChart chart = chartBook.Charts.Add("Chart");
IWorksheet sheet = chartBook.Worksheets[ 0 ];
sheet.Name="Data";
chart.ChartType=ExcelChartType.Line; //!!!!!I need to set it as type "Lines on 2 Axes"

7 Replies

MW Melba Winshia Syncfusion Team April 17, 2007 10:47 AM UTC

Hi Lan,

You can export line chart with secondary YAxes to excel by using the following code snippets:

[C#]

//Display secondary axis.
chart.SecondaryValueAxis.IsMaxCross = false;
chart.SecondaryCategoryAxis.IsMaxCross = true;

Please refer the following sample which implements the above said feature:

http://websamples.syncfusion.com/samples/XlsIO.Windows/F59536/main.htm

Kindly let me know if you have any other questions.

Thanks,
Melba


LM Lan Mo April 18, 2007 05:23 PM UTC

Hi Melba,
Thanks for help. Your sample helps to solve the exporting line-type chart to excel. I got little issue when exporting column-type chart with seconary YAxes to excel. Please see my attached files. The column is 'STACKED' above another in excel instead of 'SIDE-BY-SIDE' in Syncfusion chart.
How can I export columns 'SIDE-BY-SIDE' ?
Thanks,
Lan

SecondYAxesBar.zip


MW Melba Winshia Syncfusion Team April 19, 2007 01:51 PM UTC

Hi Lan,

Thanks for the update.

If you have more than two series only it will be visible as 'SIDE-BY-SIDE' else it will be stacked. This is the behaviour of Excel also. Here is the sample for your reference:

http://websamples.syncfusion.com/samples/XlsIO.Windows/59536_1/main.htm

This is because we must have at least two series in a chart in order to display secondary axes and one series is needed for each axis (ie. for primary and Secondary) group. The output of XlsIO is same as Ms Excel. Here is the video clip for your reference (to create a chart in Ms Excel with secondary Axis- the output is same as XlsIO)

Default.zip

Please let me know if I am missing some thing.

Thanks,
Melba


LM Lan Mo April 19, 2007 05:42 PM UTC

Hi Melba,
Thanks for your samples and explaination.

For my situation, I only have two seriess and they have very different Y valus ranged so that I think I have to use the secondary YAxes. I've explored the excel chart a little bit and I found if I can setup the series' GAP WIDTH to 70, I can at lease see both STACKED series. Please see my attached image.

My question is:
How can I set the GAP WIDTH in XslIO?

Thanks,

Lan

charttoexcel.zip


MW Melba Winshia Syncfusion Team April 20, 2007 10:30 AM UTC

Hi Lan,

Thanks for the update.

You can set GAP WIDTH by using the GapWidth property. Please refer the following code snippets to achieve this:

[c#]

//Format DataSeries
IChartSerie chartSerie = chart.Series["Apples"];

// Gap width
chartSerie.SerieFormat.CommonSerieOptions.GapWidth = 50;

Kindly let me know if you have any other questions.

Thanks,
Melba


LM Lan Mo April 20, 2007 07:00 PM UTC

Hello Melba,
It works well.

I've set the secondary YAxes series to:
chartSerie.SerieFormat.CommonSerieOptions.GapWidth = 300 //default is 150

Now the two series are stacked together but with off-set width so we can see both of them.

Please see my attached exported excel for you info.

I realy appreciate your help.
Have a great day!


Lan

Untitled38.zip


MW Melba Winshia Syncfusion Team April 23, 2007 08:04 AM UTC

Hi Lan,

Thanks for the update.

Glad to hear that it works well. Kindly let me know if you have any other questions.

Thanks,
Melba


Loader.
Live Chat Icon For mobile
Up arrow icon