Spire.XLS for .NET is a professional Excel .NET library that can be used to any type of .NET( C#, VB.NET, ASP.NET, .NET Core) application and Java (J2SE and J2EE) application.

Tue Sep 01, 2020 8:04 am

1598946456(1).png
1598946456(1).png (102.87 KiB) Viewed 255 times
Excel to generate images are required to have three columns have values, I'll see again spire.xls No such case was found in the document. What should I do with the case as shown in the figure? Can you give me a case for reference

Saunterer
 
Posts: 16
Joined: Wed Oct 11, 2017 6:37 am

Tue Sep 01, 2020 9:21 am

Hello,

Thanks for your inquiry.
Below is the code for your reference. If there is any question, please provide your input file as well as your desired output for further investigation.
Code: Select all
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.Worksheets.Clear();
            var sheet = workbook.CreateEmptySheet();

            //Set chart data
            CreateChartData(sheet);

            //Create the chart
            CreateChart(workbook);

            workbook.SaveToFile("output.xlsx", FileFormat.Version2013);
        }
        public static void CreateChartData(Worksheet sheet)
        {
            sheet.Range["A1"].Value = "Date";
            sheet.Range["A2"].Value = "8/9/2019";
            sheet.Range["A3"].Value = "8/10/2019";
            sheet.Range["A4"].Value = "8/11/2019";
            sheet.Range["A5"].Value = "8/12/2019";
            sheet.Range["A6"].Value = "8/13/2019";
            sheet.Range["A7"].Value = "8/14/2019";
            sheet.Range["A8"].Value = "8/15/2019";
            sheet.Range["A9"].Value = "8/20/2019";

            sheet.Range["B1"].Value = "Value1";
            sheet.Range["B2"].NumberValue = 9500;
            sheet.Range["B3"].NumberValue = 7460;
            sheet.Range["B4"].NumberValue = 8000;
            sheet.Range["B5"].NumberValue = 3865;
            sheet.Range["B6"].NumberValue = 4670;
            sheet.Range["B7"].NumberValue = 4680;
            sheet.Range["B8"].NumberValue = 8640.65;
            sheet.Range["B9"].NumberValue = 6784.65;

            sheet.Range["C1"].Value = "Value2";
            sheet.Range["C2"].NumberValue = 80;
            sheet.Range["C3"].NumberValue = 63;
            sheet.Range["C4"].NumberValue = 67;
            sheet.Range["C5"].NumberValue = 32;
            sheet.Range["C6"].NumberValue = 39;
            sheet.Range["C7"].NumberValue = 39;
            sheet.Range["C8"].NumberValue = 73;
            sheet.Range["C9"].NumberValue = 57;
        }
        public static void CreateChart(Workbook workbook)
        {
            var sheet = workbook.Worksheets[0];
            var chart = workbook.Worksheets.Add("Chart").Charts.Add();
            chart.Name = "Chart";
            chart.ChartTitle = "Priced Orders";
            chart.ChartTitleArea.IsBold = true;
            chart.ChartTitleArea.Size = 12;
            chart.SeriesDataFromRange = false;
            chart.DataRange = sheet.Range["A1:C9"];

            ChartSeries series = chart.Series;
            series[0].SerieType = ExcelChartType.LineMarkers;

            series[1].SerieType = ExcelChartType.LineMarkers;
            series[1].UsePrimaryAxis = false;

            chart.SecondaryCategoryAxis.IsMaxCross = true;
            chart.Legend.Position = LegendPositionType.Right;
        }


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1512
Joined: Tue Jul 09, 2019 2:22 am

Fri Sep 04, 2020 5:46 am

Hello,

Greetings from E-iceblue!
Does my code help you? Could you please give us some feedback at your convenience?
Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1512
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.XLS