Added charts to correlation and paired T-test.

This commit is contained in:
依瑪貓 2016-09-09 00:23:11 +08:00
parent 02cb21fa44
commit bb2945ba81
5 changed files with 123 additions and 5 deletions

View File

@ -55,12 +55,71 @@ Sub subRunCorrelation As Object
' Reports the paired T-test. ' Reports the paired T-test.
subReportCorrelation (ThisComponent, mRanges (0), mRanges (1)) subReportCorrelation (ThisComponent, mRanges (0), mRanges (1))
oSheet = oSheets.getByName (sSheetName & "_correl")
' Adds an X-Y diagram.
subAddChart (oSheet, mRanges (0), mRanges (1))
' Makes the report sheet active. ' Makes the report sheet active.
oSheet = oSheets.getByName (sSheetName & "_correl")
ThisComponent.getCurrentController.setActiveSheet (oSheet) ThisComponent.getCurrentController.setActiveSheet (oSheet)
End Sub End Sub
' subAddChart: Adds a chart for the data
Sub subAddChart (oSheet As Object, oDataXRange As Object, oDataYRange As Object)
Dim oCharts As Object, oChart As Object
Dim oChartDoc As Object, oDiagram As Object
Dim aPos As New com.sun.star.awt.Rectangle
Dim mAddrs (1) As New com.sun.star.table.CellRangeAddress
Dim sTitle As String
Dim oProvider As Object, oData As Object
Dim sRange As String, mData () As Object
' Adds the chart
With aPos
.X = 0
.Y = 3510
.Width = 10000
.Height = 10000
End With
mAddrs (0) = oDataXRange.getRangeAddress
mAddrs (1) = oDataYRange.getRangeAddress
oCharts = oSheet.getCharts
oCharts.addNewByName (oSheet.getName, aPos, mAddrs, True, False)
oChart = oCharts.getByName (oSheet.getName)
oChartDoc = oChart.getEmbeddedObject
BasicLibraries.loadLibrary "XrayTool"
oDiagram = oChartDoc.createInstance ( _
"com.sun.star.chart.XYDiagram")
oDiagram.setPropertyValue ("Lines", False)
oDiagram.setPropertyValue ("HasXAxisGrid", False)
oDiagram.setPropertyValue ("HasYAxisGrid", False)
sTitle = oDataXRange.getCellByPosition (0, 0).getString
oDiagram.getXAxisTitle.setPropertyValue ("String", sTitle)
sTitle = oDataYRange.getCellByPosition (0, 0).getString
oDiagram.getYAxisTitle.setPropertyValue ("String", sTitle)
oChartDoc.setDiagram (oDiagram)
oProvider = oChartDoc.getDataProvider
mData = oChartDoc.getDataSequences
sRange = oDataXRange.getCellByPosition(0, 0).getPropertyValue ("AbsoluteName")
oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
mData (0).setLabel (oData)
sRange = oDataXRange.getCellRangeByPosition(0, 1, 0, oDataXRange.getRows.getCount - 1).getPropertyValue ("AbsoluteName")
oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
oData.Role = "values-x"
mData (0).setValues (oData)
sRange = oDataYRange.getCellByPosition(0, 0).getPropertyValue ("AbsoluteName")
oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
mData (1).setLabel (oData)
sRange = oDataYRange.getCellRangeByPosition(0, 1, 0, oDataYRange.getRows.getCount - 1).getPropertyValue ("AbsoluteName")
oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
oData.Role = "values-y"
mData (1).setValues (oData)
oChartDoc.setPropertyValue ("HasLegend", False)
End Sub
' subReportCorrelation: Reports the Pearsons correlation coefficient ' subReportCorrelation: Reports the Pearsons correlation coefficient
Sub subReportCorrelation (oDoc As Object, oDataXRange As Object, oDataYRange As Object) Sub subReportCorrelation (oDoc As Object, oDataXRange As Object, oDataYRange As Object)
Dim oSheets As Object, sSheetName As String Dim oSheets As Object, sSheetName As String

View File

@ -55,12 +55,71 @@ Sub subRunPairedTTest As Object
' Reports the paired T-test. ' Reports the paired T-test.
subReportPairedTTest (ThisComponent, mRanges (0), mRanges (1)) subReportPairedTTest (ThisComponent, mRanges (0), mRanges (1))
oSheet = oSheets.getByName (sSheetName & "_ttest")
' Adds an X-Y diagram.
subAddChart (oSheet, mRanges (0), mRanges (1))
' Makes the report sheet active. ' Makes the report sheet active.
oSheet = oSheets.getByName (sSheetName & "_ttest")
ThisComponent.getCurrentController.setActiveSheet (oSheet) ThisComponent.getCurrentController.setActiveSheet (oSheet)
End Sub End Sub
' subAddChart: Adds a chart for the data
Sub subAddChart (oSheet As Object, oDataXRange As Object, oDataYRange As Object)
Dim oCharts As Object, oChart As Object
Dim oChartDoc As Object, oDiagram As Object
Dim aPos As New com.sun.star.awt.Rectangle
Dim mAddrs (1) As New com.sun.star.table.CellRangeAddress
Dim sTitle As String
Dim oProvider As Object, oData As Object
Dim sRange As String, mData () As Object
' Adds the chart
With aPos
.X = 0
.Y = 10000
.Width = 10000
.Height = 10000
End With
mAddrs (0) = oDataXRange.getRangeAddress
mAddrs (1) = oDataYRange.getRangeAddress
oCharts = oSheet.getCharts
oCharts.addNewByName (oSheet.getName, aPos, mAddrs, True, False)
oChart = oCharts.getByName (oSheet.getName)
oChartDoc = oChart.getEmbeddedObject
BasicLibraries.loadLibrary "XrayTool"
oDiagram = oChartDoc.createInstance ( _
"com.sun.star.chart.XYDiagram")
oDiagram.setPropertyValue ("Lines", False)
oDiagram.setPropertyValue ("HasXAxisGrid", False)
oDiagram.setPropertyValue ("HasYAxisGrid", False)
sTitle = oDataXRange.getCellByPosition (0, 0).getString
oDiagram.getXAxisTitle.setPropertyValue ("String", sTitle)
sTitle = oDataYRange.getCellByPosition (0, 0).getString
oDiagram.getYAxisTitle.setPropertyValue ("String", sTitle)
oChartDoc.setDiagram (oDiagram)
oProvider = oChartDoc.getDataProvider
mData = oChartDoc.getDataSequences
sRange = oDataXRange.getCellByPosition(0, 0).getPropertyValue ("AbsoluteName")
oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
mData (0).setLabel (oData)
sRange = oDataXRange.getCellRangeByPosition(0, 1, 0, oDataXRange.getRows.getCount - 1).getPropertyValue ("AbsoluteName")
oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
oData.Role = "values-x"
mData (0).setValues (oData)
sRange = oDataYRange.getCellByPosition(0, 0).getPropertyValue ("AbsoluteName")
oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
mData (1).setLabel (oData)
sRange = oDataYRange.getCellRangeByPosition(0, 1, 0, oDataYRange.getRows.getCount - 1).getPropertyValue ("AbsoluteName")
oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
oData.Role = "values-y"
mData (1).setValues (oData)
oChartDoc.setPropertyValue ("HasLegend", False)
End Sub
' subReportPairedTTest: Reports the paired T-test ' subReportPairedTTest: Reports the paired T-test
Sub subReportPairedTTest (oDoc As Object, oDataXRange As Object, oDataYRange As Object) Sub subReportPairedTTest (oDoc As Object, oDataXRange As Object, oDataYRange As Object)
Dim oSheets As Object, sSheetName As String Dim oSheets As Object, sSheetName As String

View File

@ -72,9 +72,9 @@ Sub subRunIndependentTTest As Object
' Reports the independent T-test. ' Reports the independent T-test.
subReportIndependentTTest (ThisComponent, mRanges (0), mRanges (1)) subReportIndependentTTest (ThisComponent, mRanges (0), mRanges (1))
oSheet = oSheets.getByName (sSheetName & "_ttest")
' Makes the report sheet active. ' Makes the report sheet active.
oSheet = oSheets.getByName (sSheetName & "_ttest")
ThisComponent.getCurrentController.setActiveSheet (oSheet) ThisComponent.getCurrentController.setActiveSheet (oSheet)
End Sub End Sub

View File

@ -72,9 +72,9 @@ Sub subRunANOVA As Object
' Reports the ANOVA (Analyze of Variances) ' Reports the ANOVA (Analyze of Variances)
subReportANOVA (ThisComponent, mRanges (0), mRanges (1)) subReportANOVA (ThisComponent, mRanges (0), mRanges (1))
oSheet = oSheets.getByName (sSheetName & "_anova")
' Makes the report sheet active. ' Makes the report sheet active.
oSheet = oSheets.getByName (sSheetName & "_anova")
ThisComponent.getCurrentController.setActiveSheet (oSheet) ThisComponent.getCurrentController.setActiveSheet (oSheet)
End Sub End Sub

View File

@ -55,9 +55,9 @@ Sub subRunChi2GoodnessOfFit As Object
' Reports the chi-square goodness of fit ' Reports the chi-square goodness of fit
subReportChi2GoodnessOfFit (ThisComponent, mRanges (0), mRanges (1)) subReportChi2GoodnessOfFit (ThisComponent, mRanges (0), mRanges (1))
oSheet = oSheets.getByName (sSheetName & "_chi2")
' Makes the report sheet active. ' Makes the report sheet active.
oSheet = oSheets.getByName (sSheetName & "_chi2")
ThisComponent.getCurrentController.setActiveSheet (oSheet) ThisComponent.getCurrentController.setActiveSheet (oSheet)
End Sub End Sub