none
Q2: Creating a combined chart in code RRS feed

  • Question

  • Hi all;

    I'm trying to create a chart in my AddIn (C#, COM - not VSTO). This chart has several series that may be of different types (i.e. column and line). And I have the data for each individual series held separately, even though several series may have the same X axis data points. 

    If all the series are the same chart type, then I do I set just ChartObject.Chart.ChartType? But if I have several types, then I do not set ChartObject.Chart.ChartType and instead for each series do I set Series.SeriesType for each?

    thanks - dave

    Question broken out as requested by Bruce Dai. Bruce, if the above is not sufficient, please tell me what more you need for clarification.


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Thursday, October 25, 2018 12:21 PM

Answers

  • Hi Dave,

    >> If all the series are the same chart type, then I do set just ChartObject.Chart.ChartType? But if I have several types, then I do not set ChartObject.Chart.ChartType and instead for each series do I set Series.SeriesType for each?

    We could apply different chart type to different series, please try the following link for reference:

    var cs1 = (ChartSerie)chart.Series[0];
    cs1.SerieType = ExcelChartType.ColumnClustered;
    var cs2 = (ChartSerie)chart.Series[1];
    cs2.SerieType = ExcelChartType.ColumnClustered;     
    var cs3 = (ChartSerie)chart.Series[2];
    cs3.SerieType = ExcelChartType.LineMarkers;
    

    For more information, please review the following link:

    How to Create a Combination Chart in Excel in C#

    Looking forward to hearing from you.

    Best Regards,

    Yuki


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    • Marked as answer by DavidThi808 Friday, October 26, 2018 3:04 PM
    Friday, October 26, 2018 3:31 AM
    Moderator

All replies

  • Hi Dave,

    >> If all the series are the same chart type, then I do set just ChartObject.Chart.ChartType? But if I have several types, then I do not set ChartObject.Chart.ChartType and instead for each series do I set Series.SeriesType for each?

    We could apply different chart type to different series, please try the following link for reference:

    var cs1 = (ChartSerie)chart.Series[0];
    cs1.SerieType = ExcelChartType.ColumnClustered;
    var cs2 = (ChartSerie)chart.Series[1];
    cs2.SerieType = ExcelChartType.ColumnClustered;     
    var cs3 = (ChartSerie)chart.Series[2];
    cs3.SerieType = ExcelChartType.LineMarkers;
    

    For more information, please review the following link:

    How to Create a Combination Chart in Excel in C#

    Looking forward to hearing from you.

    Best Regards,

    Yuki


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    • Marked as answer by DavidThi808 Friday, October 26, 2018 3:04 PM
    Friday, October 26, 2018 3:31 AM
    Moderator
  • perfect - thanks - dave

    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Friday, October 26, 2018 2:36 PM