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

Xlsio chart.ChartType property

Hi all,

i'm trying to create a chart with different series types. I think i must use the "Combination_Chart" property (see code below). But there is always an exception if i run the code. Could you give me a tip what i'm doing wrong.

IWorkbook chartBook = ExcelUtils.CreateWorkbook(1);

create chart worksheet IChart chart = chartBook.Charts.Add("TestChart");

chart.ChartType = ExcelChartType.Combination_Chart;

IChartSerie series = chart.Series.Add(ChartWebControl.Series[i].Name);


if ((ChartWebControl.Series[i].Type == ChartSeriesType.Line) || (ChartWebControl.Series[i].Type == ChartSeriesType.Area))
{ series.SerieFormat.LineProperties.LineColor = ChartWebControl.Series[i].Style.Interior.BackColor;
}

if (ChartWebControl.Series[i].Type == ChartSeriesType.Line)
{
series.SerieType = ExcelChartType.Line;
}

if (ChartWebControl.Series[i].Type == ChartSeriesType.Column)
{
series.SerieType = ExcelChartType.Column_Clustered;
}

if (ChartWebControl.Series[i].Type == ChartSeriesType.Area)
{
series.SerieType = ExcelChartType.Area;
}

Regards,
Stephan


12 Replies

SD Steffen Dunst June 8, 2008 10:37 AM UTC

This code is correct, sorry

>Hi all,

i'm trying to create a chart with different series types. I think i must use the "Combination_Chart" property (see code below). But there is always an exception if i run the code. Could you give me a tip what i'm doing wrong.

IWorkbook chartBook = ExcelUtils.CreateWorkbook(1);

IChart chart = chartBook.Charts.Add("TestChart");

chart.ChartType = ExcelChartType.Combination_Chart;

IChartSerie series = chart.Series.Add(ChartWebControl.Series[i].Name);


if ((ChartWebControl.Series[i].Type == ChartSeriesType.Line) || (ChartWebControl.Series[i].Type == ChartSeriesType.Area))
{ series.SerieFormat.LineProperties.LineColor = ChartWebControl.Series[i].Style.Interior.BackColor;
}

if (ChartWebControl.Series[i].Type == ChartSeriesType.Line)
{
series.SerieType = ExcelChartType.Line;
}

if (ChartWebControl.Series[i].Type == ChartSeriesType.Column)
{
series.SerieType = ExcelChartType.Column_Clustered;
}

if (ChartWebControl.Series[i].Type == ChartSeriesType.Area)
{
series.SerieType = ExcelChartType.Area;
}

Regards,
Stephan





YG Yavanaarasi G Syncfusion Team June 10, 2008 03:57 AM UTC

Hi Stephan,

Thank you for your update.

Please let me know if you have any other concerns.

Regards,
G.Yavana



SD Steffen Dunst June 10, 2008 05:30 AM UTC

Hi,

i mean that the code in second post from me is correct copied from my original code (in the first post was a comment line wrongly copied), but i doesn't work. There is always an exception in the line

chart.ChartType = ExcelChartType.Combination_Chart;

Regards,
Stephan



YG Yavanaarasi G Syncfusion Team June 10, 2008 12:21 PM UTC

Hi Stephan,

We are looking into the issue. In the mean time could you please provide the exception details with the stack trace it will be helpful for reproducing the issue in our side?

Regards,
G.Yavana



SD Steffen Dunst June 10, 2008 12:41 PM UTC

Hi,

Error Screen ic enclosed in the document.

Stephan



ErrorScreen_d14e60bc.zip


YG Yavanaarasi G Syncfusion Team June 12, 2008 10:00 AM UTC

Hi Stephan,

If you want to set the chart type as combination chart you have to set different serie type and then apply the combination chart. Because Combination chart represents combination with different serie types.

Please refer the below code:

[C#]
serieOne.SerieType = ExcelChartType.Line;
serietwo.SerieType = ExcelChartType.Column_Clustered;
shape.ChartType = ExcelChartType.Combination_Chart;


Here is the sample for your reference:

http://websamples.syncfusion.com/samples/XlsIO.Web/6.2.0.40/Combination_chart/main.htm

Please try this and let me know if this helps.

Regards,
G.Yavana




SD Steffen Dunst June 13, 2008 08:22 AM UTC

Hi,

that looks fine and works perfectly.

Regards,
Stephan



YG Yavanaarasi G Syncfusion Team June 13, 2008 10:54 AM UTC

Hi Stephan,

Thank you for your update.

Glad to hear that the problem has been solved.

Please let me know if you have any other questions.

Regards,
G.Yavana



SD Steffen Dunst June 18, 2008 02:43 PM UTC

Is it possible to get the code to the example? The following link is not reachable

http://websamples.syncfusion.com/samples/XlsIO.Web/6.2.0.40/Combination_chart/main.htm

Regards,
Stephan



YG Yavanaarasi G Syncfusion Team June 19, 2008 01:44 PM UTC

Hi Stephan,

Please refer the below code:




//New instance of XlsIO is created.[Equivalent to launching MS Excel with no workbooks open].
//The instantiation process consists of two steps.

//Step 1 : Instantiate the spreadsheet creation engine.
ExcelEngine excelEngine = new ExcelEngine();
//Step 2 : Instantiate the excel application object.
IApplication application = excelEngine.Excel;

//A new workbook is created.[Equivalent to creating a new workbook in MS Excel]
//The new workbook will have 2 worksheets
IWorkbook workbook = application.Workbooks.Create(1);
//The first worksheet object in the worksheets collection is accessed.
IWorksheet sheet = workbook.Worksheets[0];
sheet.Name = "CombinationCharts";

//Entering the Datas for the chart
sheet.Range["A1"].Text = "Texas books Unit sales";
sheet.Range["A1:C1"].Merge();
sheet.Range["A1"].CellStyle.Font.Bold = true;

sheet.Range["B2"].Text = "Jan";
sheet.Range["C2"].Text = "Feb";


sheet.Range["A3"].Text = "Austin";
sheet.Range["A4"].Text = "Dallas";
sheet.Range["A5"].Text = "Houston";
sheet.Range["A6"].Text = "San Antonio";

sheet.Range["B3"].Number = 53.75;
sheet.Range["B4"].Number = 52.85;
sheet.Range["B5"].Number = 59.77;
sheet.Range["B6"].Number = 96.15;

sheet.Range["C3"].Number = 79.79;
sheet.Range["C4"].Number = 59.22;
sheet.Range["C5"].Number = 10.09;
sheet.Range["C6"].Number = 73.02;

//Adding a New(Embedded chart) to the Worksheet
IChartShape shape = sheet.Charts.Add();


shape.DataRange = sheet.Range["B3:C6"];
shape.PrimaryCategoryAxis.Title = "City";
shape.PrimaryValueAxis.Title = "Sales (in Dollars)";
shape.ChartTitle = "Texas Books Unit Sales";


//Setting the Serie Names in a Legend
IChartSerie serieOne = shape.Series[0];
serieOne.Name = "Jan";
IChartSerie serietwo = shape.Series[1];
serietwo.Name = "Feb";


//Setting the (Rows & Columns)Property for the Embedded chart.
shape.BottomRow = 40;
shape.TopRow = 10;
shape.LeftColumn = 3;
shape.RightColumn = 15;

//Setting Chart type for individual series.
serieOne.SerieType = ExcelChartType.Line;
serietwo.SerieType = ExcelChartType.Column_Clustered;

shape.ChartType = ExcelChartType.Combination_Chart;

//Saving the workbook to disk.

workbook.SaveAs(@"Output.xls", ExcelSaveType.SaveAsXLS, Response, ExcelDownloadType.PromptDialog);

//Close the workbook.
workbook.Close();

//No exception will be thrown if there are unsaved workbooks.
excelEngine.ThrowNotSavedOnDestroy = false;
excelEngine.Dispose();



Let me know if you have any other questions.

Regards,
G.Yavana



SD Steffen Dunst June 19, 2008 02:34 PM UTC

Hi,
thank's for reply. One question. I'm using the IChart Interface and not the IChartShape Interface. Could you explain me the difference?

Thank's,
Stephan



YG Yavanaarasi G Syncfusion Team June 20, 2008 07:26 AM UTC

Hi Stephan,

By using Ichart interface you cannot set the position of the chart. But IChartShape interface represents the embedded chart that is we can set the position of the chart.

Please let me know if you have any other questions.

Regards,
G.Yavana


Loader.
Live Chat Icon For mobile
Up arrow icon