Add second y-axis to excel plot

2 次查看(过去 30 天)
Ellie
Ellie 2012-10-12
Chart = invoke(Workbook.Charts,'Add');
Chart.ChartType = 'xlXYScatterSmooth';
Chart.Axes(1).HasTitle = true;
Chart.Axes(1).AxisTitle.Text = 'Time (sec)';
Chart.Axes(2).HasTitle = true;
Chart.Axes(2).AxisTitle.Text = 'Pressure (psig/psid)';
Chart.Axes(2,2).HasTitle = true;
Chart.Axes(2,2).AxisTitle.Text = 'RPM and Flows (pph)';
invoke(Chart, 'SetSourceData', Excel.Range('Sheet1!A3:D6'));
If I use:
Chart.Axes(2,2).HasTitle = true;
Chart.Axes(2,2).AxisTitle.Text = 'RPM and Flows (pph)';
to obtain the second y axis, I get the following message:
Error using Interface.000208D6_0000_0000_C000_000000000046/Axes
Invoke Error, Dispatch Exception: Unspecified error
Error in Trial (line 14)
Chart.Axes(2,2).HasTitle = true;
How can a second y-axis be added to the right of the chart?

回答(1 个)

Julian Hapke
Julian Hapke 2014-6-23
hi anda,
if you have data in your chart, that's supposed to be scaled to the secondary y-axis, just move the plot there, here's an example:
xls = actxserver('Excel.Application');
xls.Visible=true;
a=num2cell([(1:10)' (1:10)' (10.^(1:10))']);
wb=xls.Workbooks.Add;
set(wb.ActiveSheet.Range('$A$1:$C$10'),'Value',a);
crt=wb.ActiveSheet.Shapes.AddChart(75);
getscale(crt)
s2=crt.Chart.SeriesCollection(2);
set(s2,'AxisGroup','xlSecondary');
if you just want the other axis with only one plot, you need some dummy data.
regards
julian

类别

Help CenterFile Exchange 中查找有关 Bar Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by