Search code examples
exceloffice-scripts

Chart Formatting in Excel Scripts


im relativley new to Excel Scripts and i need your help.

I have build an Excel Script which i want to add to my power automate flow, to generate graphs automatically with a predefined template.

In general i want to add vertical gridlines to the graph so that it becomes easier for the reader to look at the data. On the right side i haven't figured out how to set the x-Axis with the labels to the bottom of the graph, now it does not look uniform with regards to the left graph.

any help is appreciated :)

// Formating Graph1 //-----------------------------------------------

AAchart.getTitle().setVisible(false);
AAchart.getLegend().setVisible(false);


AAseriesC.getFormat().getLine().setColor("#00B050");
AAseriesG.getFormat().getLine().setColor("#FF0000");
AAseriesH.getFormat().getLine().setColor("#00B050"); //green

let AALineFormatC = AAseriesC.getFormat().getLine();
AALineFormatC.setWeight(2);
let AALineFormatG = AAseriesG.getFormat().getLine();
AALineFormatG.setWeight(2);
let AALineFormatH = AAseriesH.getFormat().getLine();
AALineFormatH.setWeight(2);

AAseriesC.setMarkerStyle(ExcelScript.ChartMarkerStyle.none);
AAseriesG.setMarkerStyle(ExcelScript.ChartMarkerStyle.none);
AAseriesH.setMarkerStyle(ExcelScript.ChartMarkerStyle.none);

let AAseriesAB = AAchart.getSeries()[0];
AAseriesAB.setMarkerStyle(ExcelScript.ChartMarkerStyle.circle);
AAseriesAB.setMarkerBackgroundColor("#FFFFFF");
AAseriesAB.setMarkerSize(6);

enter image description here



Solution

  • Relocate Axis-X location to bottom of the chart.

    Microsoft documentation:

    ExcelScript.ChartAxis interface setPosition(position)

    ExcelScript.ChartAxis interface getMinimum()

    function main(workbook: ExcelScript.Workbook) {
        let sht = workbook.getActiveWorksheet();
        let cht = sht.getCharts()[0];
        let axisX = cht.getAxes().getValueAxis();
        // axisX.setPosition(ExcelScript.ChartAxisPosition.automatic);
        axisX.setPosition(ExcelScript.ChartAxisPosition.custom) ;
        axisX.setPositionAt(axisX.getMinimum());
    }
    

    enter image description here