Add second y-axis to excel plot
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Bar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!