Excel chart, change MinimumScale X-axis

2 次查看(过去 30 天)
Hello Matlab community,
I would like to change the minimum scale of the X-axis. It works for the Y-axis, but for the X-axis there is always an error.
The part that causes me problems is this.
chart1.Axes(1).MinimumScaleIsAuto = 1;
chart1.Axes(1).MaximumScaleIsAuto = 1;
chart1.Axes(1).MinorUnitIsAuto = 1;
chart1.Axes(1).MajorUnitIsAuto = 1;
It would be fantastic if someone here could help me.
ewb = excelApp.Workbooks.Open('Put file Path here');
myWorkSheet = ewb.Worksheets.get('Item', 1);
rg1 = myWorkSheet.Range('$A:$A'); %getting x axis data from excel sheet column A
rg2 = myWorkSheet.Range('$B:$B'); %getting x axis data from excel sheet column B
rg = excelApp.Union(rg1, rg2);
chart1 = ewb.Charts.Add;
chart1.SetSourceData(rg); %Adding data to chart from excel sheet
chart1.ChartType = 'xlLine'; %defining chart type
chart1.Axes(1).HasTitle = true;
chart1.Axes(1).AxisTitle.Text = 'X axis Title'; % XAxes
chart1.Axes(1).HasMajorGridlines = 1;
chart1.Axes(1).Select;
chart1.Axes(1).MinimumScaleIsAuto = 1;
chart1.Axes(1).MaximumScaleIsAuto = 1;
chart1.Axes(1).MinorUnitIsAuto = 1;
chart1.Axes(1).MajorUnitIsAuto = 1;
chart1.Axes(2).HasTitle = true;
chart1.Axes(2).AxisTitle.Text = 'Y axis Title'; %YAxes
chart1.Axes(2).HasMajorGridlines = 1;
chart1.Axes(2).Select;
chart1.Axes(2).MinimumScaleIsAuto = 1;
chart1.Axes(2).MaximumScaleIsAuto = 1;
chart1.Axes(2).MinorUnitIsAuto = 1;
chart1.Axes(2).MajorUnitIsAuto = 1;
ewb.Save
ewb.Close(false)
excelApp.Quit

回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by