Excel Chart with 2 X-axis through matlab

2 visualizaciones (últimos 30 días)
Moh
Moh el 24 de Nov. de 2014
Editada: Moh el 28 de Nov. de 2014
I want to make a program that will make an Excel chart with 2 X-axis and Y-axis. how can I add the second X-axis?
my second X-axis is 'Sheet2', C3: C ...
here is my code
Excel = actxserver('excel.application');
% Get Workbook object
WB = Excel.Workbooks.Open(outname);
% Get neu Worksheets object
WS = WB.Worksheets;
WS.Add([], WS.Item(WS.Count));
Sheet=WB.Worksheets.Item('Sheet2');
Charts = WB.Charts;
Chart = invoke(Charts,'Add');
invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
Excel.ActiveChart.SeriesCollection(1).Name = 'Temberatur';
Excel.ActiveChart.SeriesCollection(1).XValues = Sheet.Range(strcat('B3:B',num2str(C)));
Excel.ActiveChart.SeriesCollection(1).Values = Sheet.Range(strcat('A3:A',num2str(C)));
% Setting the Chart Sheet Title & Chart Title.
Excel.ActiveChart.HasTitle = 1;
Excel.ActiveChart.ChartTitle.Characters.Text = 'Temperature';
Excel.ActiveChart.Name = 'Temperatur';
% Setting the (X-Axis) and (Y-Axis) titles.
ChartAxes = invoke(Chart,'Axes',1);
set(ChartAxes,'HasTitle',1);
set(ChartAxes.AxisTitle,'Caption','Temperature /°C');
ChartAxes = invoke(Chart,'Axes',2);
set(ChartAxes,'HasTitle',2);
set(ChartAxes.AxisTitle,'Caption','Depth /m');
Excel.ActiveChart.ChartType = 65;
% Setting the (Y-Axis) Scale
Excel.ActiveChart.Axes(2).Select;
Excel.ActiveChart.Axes(2).MinimumScale = 0;
Excel.ActiveChart.Axes(2).MaximumScale = max(handles.tiefe(:,C));
Excel.ActiveChart.Axes(2).ReversePlotOrder = true;

Respuesta aceptada

Moh
Moh el 28 de Nov. de 2014
Editada: Moh el 28 de Nov. de 2014
I have found the solution with
Excel.ActiveChart.ChartType = 65;
can not make 2 X-axis . I did that on ChartType = 73 and worked very well
Here the list of chart type
hier ist mein end Code
Excel = actxserver('excel.application');
% Get Workbook object
WB = Excel.Workbooks.Open(outname);
% Get neu Worksheets object
WS = WB.Worksheets;
WS.Add([], WS.Item(WS.Count));
Sheet=WB.Worksheets.Item('Ergebnis');
Charts = WB.Charts;
Chart = invoke(Charts,'Add');
invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
Excel.ActiveChart.SeriesCollection(1).Name = 'Temperatur der Erdr';
Excel.ActiveChart.SeriesCollection(1).XValues=Sheet.Range(strcat('B3:B',num2str(C)));
Excel.ActiveChart.SeriesCollection(1).Values =Sheet.Range(strcat('A3:A',num2str(C)));
invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
Excel.ActiveChart.SeriesCollection(2).Name = 'Temperatur der CO2';
Excel.ActiveChart.SeriesCollection(2).XValues=Sheet.Range(strcat('C3:C',num2str(C)));
Excel.ActiveChart.SeriesCollection(2).Values=Sheet.Range(strcat('A3:A',num2str(C)));
invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
Excel.ActiveChart.SeriesCollection(3).Name = 'Temperatur der Wand';
Excel.ActiveChart.SeriesCollection(3).XValues=Sheet.Range(strcat('I3:I',num2str(C)));
Excel.ActiveChart.SeriesCollection(3).Values=Sheet.Range(strcat('A3:A',num2str(C)));
% Setting the Chart Sheet Title & Chart Title.
Excel.ActiveChart.HasTitle = 1;
Excel.ActiveChart.ChartTitle.Characters.Text = 'Temperatur';
Excel.ActiveChart.Name = 'Temperatur';
% Setting the (X-Axis) and (Y-Axis) titles.
ChartAxes = invoke(Chart,'Axes',1);
set(ChartAxes,'HasTitle',1);
set(ChartAxes.AxisTitle,'Caption','Temperatur /°C');
ChartAxes = invoke(Chart,'Axes',2);
set(ChartAxes,'HasTitle',2);
set(ChartAxes.AxisTitle,'Caption','Tiefe /m');
Excel.ActiveChart.ChartType = 73;
temp=[handles.T,handles.T_E,handles.Twz];
% Setting the (X-Axis) Scale
Excel.ActiveChart.Axes(1).Select;
Excel.ActiveChart.Axes(1).MinimumScale = min(temp(:));
Excel.ActiveChart.Axes(1).MaximumScale = max(temp(:));
% Setting the (Y-Axis) Scale
Excel.ActiveChart.Axes(2).Select;
Excel.ActiveChart.Axes(2).MinimumScale = 0;
Excel.ActiveChart.Axes(2).MaximumScale = max(handles.tiefe(:,C));
Excel.ActiveChart.Axes(2).ReversePlotOrder = true;
WB.Save();
WB.Close;

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by