none
How to Generate Excel Chart like this RRS feed

  • Question

  • Hello MSDNs

    I have Strong Requirement to generate Excel sheet with 100 charts with  different data x y every thing keep chages but pattern remains same 

    I am extracting  data from DataTable 2 excel . once data in excel  i am generating charts also but i am not able to Generate the Label with in CHarts 

    SO , i have new idea Store the template in Memory and Use it when ever its i requirement but i want know how to automate the 

    Label data charts header etc ... legend info etc 

    Thanks

    Ranjtih 


    Ranjith@Learner @Microsoft products

    Friday, May 20, 2016 9:19 AM

Answers

  • Hi Ranjtih,

    What do you mean with label data and charts header? Do you mean the Chart Title? Do you want to achieve with Office automation or Open XML SDK?

    Here is a simple code in VBA:

    Sub Macro6()
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.ChartTitle.Select
        ActiveChart.SetElement (msoElementChartTitleNone)
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 273.75, _
            190.8750393701, 68.25, 17.25).Select
        Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "Test" & Chr(13) & ""
        Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 5).ParagraphFormat. _
            FirstLineIndent = 0
        With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 5).Font
            .NameComplexScript = "+mn-cs"
            .NameFarEast = "+mn-ea"
            .Size = 11
            .Name = "+mn-lt"
        End With
    End Sub

    If you want a C# code, please refer the related C# object according this VBA code.

    # Chart interface
    https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.chart.aspx

    # Shapes interface
    https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.shapes.aspx

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, May 23, 2016 3:08 AM

All replies

  • Hi Ranjtih,

    What do you mean with label data and charts header? Do you mean the Chart Title? Do you want to achieve with Office automation or Open XML SDK?

    Here is a simple code in VBA:

    Sub Macro6()
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.ChartTitle.Select
        ActiveChart.SetElement (msoElementChartTitleNone)
        ActiveSheet.ChartObjects("Chart 1").Activate
        ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 273.75, _
            190.8750393701, 68.25, 17.25).Select
        Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "Test" & Chr(13) & ""
        Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 5).ParagraphFormat. _
            FirstLineIndent = 0
        With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 5).Font
            .NameComplexScript = "+mn-cs"
            .NameFarEast = "+mn-ea"
            .Size = 11
            .Name = "+mn-lt"
        End With
    End Sub

    If you want a C# code, please refer the related C# object according this VBA code.

    # Chart interface
    https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.chart.aspx

    # Shapes interface
    https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.shapes.aspx

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, May 23, 2016 3:08 AM
  • Hi, here is a very straightforward way to create column chart in C#, you only need to change the Chart.DataRange so as to create multiple charts based on different data. Also, it enables you to custom the data labels, header title, legend info, etc.

    Generate Excel Column Chart inC#


    Friday, June 17, 2016 8:37 AM