Add second y-axis to excel plot

1 visualización (últimos 30 días)
Ellie
Ellie el 12 de Oct. de 2012
Respondida: Julian Hapke el 23 de Jun. de 2014
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?

Respuestas (1)

Julian Hapke
Julian Hapke el 23 de Jun. de 2014
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

Categorías

Más información sobre Bar Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by