There is a part of Delphi code:

chart:=sheet.chartobjects.add(270,205,397,220); chart.chart.charttype:=4; chart.Chart.SetSourceData(Sheet.Range['A3:B34']); 

which displays in Excel graph (chart):

enter image description here

I need another type of graphics, through the macro (excel-vba) it looks like this:

 ActiveSheet.Shapes.AddChart2(332, xlLineMarkersStacked).Select 

Question: what code on Delphi should be executed instead of this line, so that it will bring me this type of graphics:

enter image description here

    1 answer 1

    You just need to replace

     chart.chart.charttype:=4; 

    on

     chart.chart.charttype:=66; // xlLineMarkersStacked = 66 

    to change the type of diagram to the desired one.

    If you often have to use the construction of diagrams in Excel inside Delphi-programs, you should start a module, where the main constants will be listed. Here are all the enumeration constants for Excel charts, copy them to a new unit, design as const and it will be easier for you to translate Excel macros into Delphi code.

    • Thanks for the help) - Amirhon
    • one more thing: how to remove the shape of the legend? - Amirhon
    • @ Amirhon in your code like this: chart.Chart.haslegend: = false; - Viktor Tomilov
    • All the problem is solved, thank you again)) - Amirhon
    • @ Amirhon You 're welcome :) - Viktor Tomilov