Top > OOoBasic > Calc > chart2 > ex6

データ範囲の変更 Edit

XYチャートのデータ範囲を変更する例です。

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
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 = "com.sun.star.chart2.template.LineSymbol"
  oChartTypeManager = oChart.getChartTypeManager()
  oChartTypeTemplate = oChartTypeManager.createInstance(sTemplateName)
  
  oChartTypeTemplate.changeDiagramData(_
        oDiagram, oDataSource, Array())
End Sub
 
 
Function CreateLabeledSequence(_
  oDataProvider, _
  sDataRange, _
  sRole, _
  Optional sLabelRange)
  
  oLabeledSeq = CreateUnoService("com.sun.star.chart2.data.LabeledDataSequence")
  
  oYDataSequence = CreateDataSequence(oDataProvider, sDataRange, sRole)
  oLabeledSeq.setValues(oYDataSequence)
  
  If NOT IsMissing(sLabelRange) Then
    oLabelDataSequence = CreateDataSequence(oDataProvider, sLabelRange, "label")
    oLabeledSeq.setLabel(oLabelDataSequence)
  End If
  
  CreateLabeledSequence = oLabeledSeq
End Function
 
 
' creat new DataSequence from range representaion
' that provides real data and its role in the series
' oDataProvider: com.sun.star.chart2.data.XDataProvider
' sRangeRepresentation: range address e.g. Sheet1.A1:B2
' sRole: role is defined in com.sun.star.chart2.data.DataSequenceRole
Function CreateDataSequence( _
    oDataProvider As Object, _
    sRangeRepresentation As String, sRole As String ) As Object
 
  Dim oDataSequence As Object
  On Error GoTo Handler
  ' create .chart2.data.DataSequence from range representation
  If oDataProvider._
      createDataSequenceByRangeRepresentationPossible(sRangeRepresentation) Then
    oDataSequence = oDataProvider._
        createDataSequenceByRangeRepresentation(sRangeRepresentation)
    If NOT IsNull(oDataSequence) Then
      oDataSequence.Role = sRole
    End If
  End If
 
  Handler:
    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