Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implete the chart which is a combination of two charts (Column and Line). #57

Closed
ksq1063126847 opened this issue Sep 17, 2019 · 2 comments

Comments

@ksq1063126847
Copy link

ksq1063126847 commented Sep 17, 2019

  1. Here's what I want,
    Result
@ksq1063126847
Copy link
Author

This is the solution.

1. All code

public static void Run()
{
// Instantiating a Workbook object
Workbook workbook = new Workbook();

        // Obtaining the reference of the newly added worksheet by passing its sheet index
        Worksheet worksheet = workbook.Worksheets[0];

        // Adding sample values to cells
        worksheet.Cells["A1"].PutValue("Product");
        worksheet.Cells["A2"].PutValue("A");
        worksheet.Cells["A3"].PutValue("B");
        worksheet.Cells["A4"].PutValue("C");
        worksheet.Cells["A5"].PutValue("D");

        worksheet.Cells["B1"].PutValue("Count");
        worksheet.Cells["B2"].PutValue(1);
        worksheet.Cells["B3"].PutValue(2);
        worksheet.Cells["B4"].PutValue(3);
        worksheet.Cells["B5"].PutValue(4);

        worksheet.Cells["C1"].PutValue("Percent");
        worksheet.Cells["C2"].PutValue(0.1);
        worksheet.Cells["C3"].PutValue(0.2);
        worksheet.Cells["C4"].PutValue(0.3);
        worksheet.Cells["C5"].PutValue(0.4);

        // Adding a chart to the worksheet
        int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 25, 10);

        // Accessing the instance of the newly added chart
        Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];

        // Adding NSeries (chart data source) to the chart ranging from "B2" cell to "C5"
        chart.NSeries.Add("B2:C5", true);

        // Setting the chart type of 2nd NSeries to display as line chart
        chart.NSeries[0].Type = Aspose.Cells.Charts.ChartType.Column;
        chart.NSeries[1].Type = Aspose.Cells.Charts.ChartType.LineStackedWithDataMarkers;

        //设置 NSeries列名称
        chart.NSeries.CategoryData = "A2:A5";
        chart.NSeries[0].Name = "Product";
        chart.NSeries[1].Name = "Percent";

        //设置第二坐标轴
        chart.NSeries[1].PlotOnSecondAxis = true;
        chart.SecondValueAxis.IsVisible = true;

        //显示DataTable
        chart.ShowDataTable = true;
      
        // Saving the Excel file
        workbook.Save(outputDir + "outputHowToCreateCustomChart.xlsx");

        Console.WriteLine("HowToCreateCustomChart executed successfully.");
    }

2.Screenshot

Ok

@amjad-sahi
Copy link
Collaborator

Good to know that you have sorted it out now. Your chart is custom oriented which is a combination of two charts (Column and Line), so you have to write the code accordingly.

@ksq1063126847 ksq1063126847 changed the title How to Generate Column Charts with Folded Lines. How to implete the chart which is a combination of two charts (Column and Line). Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants