Dim Charts As Object
Dim chart As Object
Dim rect As Object
Dim rangeAddress(0) As Object
Set rect = oSM.Bridge_GetStruct("com.sun.star.awt.Rectangle")
Set rangeAddress(0) = oSM.Bridge_GetStruct("com.sun.star.table.CellRangeAddress")
Set Charts = oSheet.getCharts
rect.x = 2200
rect.Y = 4000
rect.Width = 35000
rect.Height = 15000
rangeAddress(0).Sheet = 0
rangeAddress(0).StartColumn = 1
rangeAddress(0).StartRow = 3
rangeAddress(0).EndColumn = x + 1
rangeAddress(0).EndRow = 5
Call Charts.addNewByName("LineChart", rect, rangeAddress(), True, True)
Set chart = Charts.getByName("LineChart").EmbeddedObject
'set as stackable bar
chart.Diagram = chart.CreateInstance("com.sun.star.chart.StackableDiagram")
chart.Diagram.Stacked = True
chart.Diagram.Percent = False
'set data series in rows
chart.Diagram.DataRowSource = Rows
This chart composed of 2 bars (see image below). Is it possible to change the colors of the data series from my program? By default it will give me orange and blue color. I found that there are something to be done with "DataSeries", but I have no idea on how to do, anyone can help me? or give me a hint?
Last edited by pu8y on Mon Nov 22, 2010 7:13 am, edited 1 time in total.
There may be something peculiar to VB, but I am largely able to reproduce your chart with OOo Basic, doing the necessary modifications to your code, and then change the series colors, to green and blue.
Sub StackedChart
Dim Charts As Object
Dim chart As Object
Dim oSheet As Object
Dim rect As new com.sun.star.awt.Rectangle
Dim rangeAddress(0) As new com.sun.star.table.CellRangeAddress
oSheet = ThisComponent.Sheets(0)
Set Charts = oSheet.getCharts
rect.x = 2200
rect.Y = 4000
rect.Width = 35000
rect.Height = 15000
rangeAddress(0).Sheet = 0
rangeAddress(0).StartColumn = 1
rangeAddress(0).StartRow = 3
rangeAddress(0).EndColumn = 13
rangeAddress(0).EndRow = 5
oSheet.Charts.addNewByName("LineChart", rect, rangeAddress(), True, True)
chart = Charts.getByName("LineChart").EmbeddedObject
'set as stackable bar
chart.Diagram = chart.CreateInstance("com.sun.star.chart.StackableDiagram")
chart.Diagram.Stacked = True
chart.Diagram.Percent = False
'set data series in rows
chart.Diagram.DataRowSource = com.sun.star.chart.ChartDataRowSource.ROWS
chart.FirstDiagram.CoordinateSystems(0).ChartTypes(0).DataSeries(0).Color = &H00FF00
chart.FirstDiagram.CoordinateSystems(0).ChartTypes(0).DataSeries(1).Color = &H0000FF
End Sub
See attached file (I entered the data from your picture). Just delete the existing chart before running the above code, changing the colors as you like.
I need to make my vb6 program to generate the .ods file with the chart, so I need to modify the code and put inside VB6 coding.
Everything goes fine, but this two rows:
pu8y wrote:I need to make my vb6 program to generate the .ods file with the chart, so I need to modify the code and put inside VB6 coding.
Everything goes fine, but this two rows:
gave me error message : "Object required", but I cannot figure out what does it means and what is missing out there.
Though it gives an error in OOo in this case, VB is often fussy about wanting Set in front of object assignments. This is a shot in the dark on my part, but try
Set chart.FirstDiagram.CoordinateSystems(0).ChartTypes(0).DataSeries(0).Color = &H00FF00
Set chart.FirstDiagram.CoordinateSystems(0).ChartTypes(0).DataSeries(1).Color = &H0000FF
Finally I am able to set the color of bars in my chart!
I used "getFirstDiagram" instead of "FirstDiagram" and "getCoordinateSystems" instead of "CoordinateSystems".