MATLAB Answers

How do I set the 'HasAxis' property of my Excel Chart object using ActiveX in MATLAB 7.11 (R2010b)?

4 views (last 30 days)
The 'HasAxis' property is used to specify whether Excel will display the primary or secondary category, series, or value axes on a chart.
The property requires that the xlAxisType and xlAxisGroup arguments are specified when the property is accessed.
How do I do that using the ACTXCONTROL ActiveX support in MATLAB?
Information about 'HasAxis' is at:

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 23 Jun 2021
Edited: MathWorks Support Team on 23 Jun 2021
The following example shows how to pass additional arguments to the SET and GET command to access a property that requires additional indexing.
% axis types: xlCategory = 1;
xlValue = 2;
% axis groups: xlPrimary = 1;
xlSecondary = 2;
% open Excel using ActiveX
xlApp = actxserver('Excel.Application');
% set it to be visible
xlApp.Visible = true;
% inhibit "Do You Want to Save" dialog when Excel is closed.
xlApp.DisplayAlerts = false;
% Add a new workbook
xlWbook = invoke(xlApp.Workbooks,'add');
% Add a blank chart to the workbook
xlChart = invoke(xlWbook.Charts,'add');
% Go to the first sheet in the workbook
xlSheet = xlWbook.Sheets.Item('Sheet1');
% insert some data
xlSheet.Range('A1:B3').Value = { 1 20 ; 2 80; 4 100 };
% set the chart to use the data for the bar values
xlChart.SetSourceData( xlSheet.Range('A1:B3'));
% get the second data series
xlS2 = xlChart.SeriesCollection.Item(2);
xlS2.AxisGroup = 'xlSecondary'; % set it to display on the secondary axis.
% get current state of primary x axis
%ans = 1
% turn off primary x axis
%ans = NaN
% verify that it's off
% ans = 0
% turn it back on
% ans = NaN
% verify that it's on
% ans = 1
% display a y axis for secondary data
set(xlChart, 'HasAxis', xlValue, xlSecondary, 1)

More Answers (0)




Community Treasure Hunt

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

Start Hunting!

Translated by