Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Mon Jun 01, 2015 7:18 am

Hi

Has anyone dot a demo in c# for this kind of chart ?

Thanks
Yosi Sender

yosisndr
 
Posts: 4
Joined: Sun May 31, 2015 7:27 am

Tue Jun 02, 2015 9:42 am

Hello,

Thanks for your inquiry.
We will look into it and let you know ASAP.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Fri Jun 05, 2015 2:33 am

Hello,

Here is the sample code for your reference.
Code: Select all
Workbook book = new Workbook();

            book.LoadFromFile("c.xlsx");

            Worksheet sheet = book.Worksheets[0];

 

 

            Chart chart = sheet.Charts.Add();

            chart.DataRange = sheet.Range["A1:M4"];

            chart.SeriesDataFromRange = true;

 

            chart.LeftColumn = 2;

            chart.TopRow = 5;

            chart.RightColumn = 15;

            chart.BottomRow = 26;

 

            // chart title

            chart.ChartTitle = "test";

            chart.ChartTitleArea.IsBold = true;

            chart.ChartTitleArea.Size = 12;

 

 

 

            chart.PrimaryCategoryAxis.CategoryType = CategoryType.Category;

            //Primary value Axis

            chart.PrimaryValueAxis.HasMajorGridLines = false;

            chart.PrimaryValueAxis.MinValue = 180;

            chart.PrimaryValueAxis.MaxValue = 500;

         

 

 

            //Secondary value Axis

            chart.SecondaryValueAxis.MaxValue = 1.5;

            chart.SecondaryValueAxis.MinValue = 0.5;

            chart.SecondaryValueAxis.MinorUnit = 0.1;

            chart.SecondaryValueAxis.MajorUnit = 0.5;

            chart.SecondaryCategoryAxis.IsMaxCross = true;

 

            var cs1 = (ChartSerie)chart.Series[0];

 

            cs1.SerieType = ExcelChartType.Line;

            cs1.Format.Options.IsVaryColor = false;

            cs1.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;

            cs1.DataPoints.DefaultDataPoint.DataLabels.Position = DataLabelPositionType.Above;

            cs1.DataFormat.MarkerStyle = ChartMarkerType.None;

            cs1.DataFormat.LineProperties.Color = System.Drawing.Color.DarkRed;

 

 

            var cs2 = (ChartSerie)chart.Series[1];

 

            cs2.SerieType = ExcelChartType.ColumnStacked;

            cs2.Format.Options.IsVaryColor = false;

            cs2.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;

            cs2.DataFormat.ForeGroundColor = Color.SaddleBrown;

            cs2.UsePrimaryAxis = false;

 

            var cs3 = (ChartSerie)chart.Series[2];

            cs3.SerieType = ExcelChartType.ColumnStacked;

            cs3.Format.Options.IsVaryColor = false;

            cs3.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;

            cs3.DataFormat.ForeGroundColor = Color.CornflowerBlue;

            cs3.UsePrimaryAxis = false;


            book.SaveToFile( "CreatelineandstackedcolumnsChart.xlsx", ExcelVersion.Version2007);


Best Regards,
Sweety

E-iceblue support team
Attachments
sample.zip
(16.55 KiB) Downloaded 341 times
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Return to Spire.XLS