Top > OOoBasic > Calc > chart2 > ex6
* データ範囲の変更 [#k364ad9e]


REM  *****  BASIC  *****

Sub CreateAndSetDataForLineChart
  oDoc = ThisComponent
  'oChart = GetSelectedChart(oDoc)
  oEmbedded = oDoc.getSheets().getByIndex(0).getCharts().getByIndex(0)
  oChart = oEmbedded.getEmbeddedObject()
  oDataProvider = oChart.getDataProvider()
  oDiagram = oChart.getFirstDiagram()
  oYDataSeq = CreateLabeledSequence(_
           oDataProvider, "$Sheet1.$B$28:$B$30", "values-y")
  oCategoriesSeq = CreateLabeledSequence(_
           oDataProvider, "$Sheet1.$A$31:$A$33", "categories")
  oDataSource = oChart.getUsedData()
  oDataSource.setData(Array(oCategoriesSeq, oYDataSeq))
  sTemplateName = ""
  oChartTypeManager = oChart.getChartTypeManager()
  oChartTypeTemplate = oChartTypeManager.createInstance(sTemplateName)
        oDiagram, oDataSource, Array())
End Sub

Function CreateLabeledSequence(_
  oDataProvider, _
  sDataRange, _
  sRole, _
  Optional sLabelRange)
  oLabeledSeq = CreateUnoService("")
  oYDataSequence = CreateDataSequence(oDataProvider, sDataRange, sRole)
  If NOT IsMissing(sLabelRange) Then
    oLabelDataSequence = CreateDataSequence(oDataProvider, sLabelRange, "label")
  End If
  CreateLabeledSequence = oLabeledSeq
End Function

' creat new DataSequence from range representaion
' that provides real data and its role in the series
' oDataProvider:
' sRangeRepresentation: range address e.g. Sheet1.A1:B2
' sRole: role is defined in
Function CreateDataSequence( _
    oDataProvider As Object, _
    sRangeRepresentation As String, sRole As String ) As Object
  Dim oDataSequence As Object
  On Error GoTo Handler
  ' create from range representation
  If oDataProvider._
      createDataSequenceByRangeRepresentationPossible(sRangeRepresentation) Then
    oDataSequence = oDataProvider._
    If NOT IsNull(oDataSequence) Then
      oDataSequence.Role = sRole
    End If
  End If
    CreateDataSequence = oDataSequence
End Function

Reload   New Lower page making Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup   Help   RSS of recent changes