To create a custom dashed line

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
misitu
Posts: 104
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

To create a custom dashed line

Post by misitu »

Hello

I have been having some trouble in figuring out how to apply

Code: Select all

LineDash.Style = com.sun.star.drawing.DashStyle.RECT,	
LineDash.Dashes = 3,			
LineDash.DotLen = 10,
LineDash.DashLen = 50,
LineDash.Distance = 2
I guess I somehow have to create a new instance of the Line Dash Style but the references are unclear.

If someone can kindly give me some example code showing how to link the above to a standard Diagram I will be very grateful.

Thanks in advance
David
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
ThierryT
Posts: 11
Joined: Fri May 13, 2016 8:52 pm

Re: To create a custom dashed line

Post by ThierryT »

An example for DashLine.

Code: Select all

Sub DefineTiret()
Dim myDocument As Object, myPage As Object, myForm As Object
Dim myTirets As New com.sun.star.drawing.LineDash
myDocument = ThisComponent
myPage = monDocument.DrawPages.getByName("Dessin3") ' get the DrawPage Dessin3 in the document
myForm = FindObjectByName(myPage, "F4") ' search the object F4 in the Draw page
With myTirets
   .Style = com.sun.star.drawing.DashStyle.RECT
   .Dots = 4 ' 4 points
   .DotLen = 50 ' of 0,5 mm
   .Dashes = 2 ' with 2 tirets
   .DashLen = 200 ' of 2 mm
   .Distance = 150 ' spaced by 1,5 mm
End With
myForm.LineWidth = 100 ' 1 mm 
myForm.LineDash = mesTirets
myForm.LineStyle = com.sun.star.drawing.LineStyle.DASH
End Sub
LibreOffice 5.3.2.1 x 64 and AOO 4.1.3 Windows x64
User avatar
misitu
Posts: 104
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

Re: To create a custom dashed line

Post by misitu »

Thank you very much, ThierryT.

It was "As New com.sun.star.drawing.LineDash" that I couldn't see for myself.

Maybe this will be the key to my understanding the uno/basic "language" a bit better.

Best regards
David
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
User avatar
misitu
Posts: 104
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

Re: To create a custom dashed line

Post by misitu »

misitu wrote:Thank you very much, ThierryT.

It was "As New com.sun.star.drawing.LineDash" that I couldn't see for myself.

Maybe this will be the key to my understanding the uno/basic "language" a bit better.

Best regards
David
oops. Spoke Too Soon.

I cannot figure out where to slot in this New Line Dash code.

As you will see below, I tried it within the diagram, nothing happened, and then outside, ditto, nothing happened.

Code: Select all

	Charts = oChartDoc.Sheets(0).Charts 'live
	Charts.addNewByName("Forex Chart", Rect, RangeAddress(), True, True)
	Chart = Charts.getByName("Forex Chart")
	ChartDoc = Chart.getEmbeddedObject()
	with ChartDoc
		.hasMainTitle = True
		.Title.String = "FOREX Last 91 Days to " & lastDateLogged
		.HasSubTitle = True
		.Subtitle.String = "(Note: EURUSD is shown 2.5x)"
		.HasLegend = True
		.Legend.Alignment = com.sun.star.chart.ChartLegendPosition.BOTTOM
		.Legend.FillColor = RGB(204, 255, 153)
		.Legend.CharHeight = 9
	end with
	ChartDoc.Diagram = ChartDoc.createInstance("com.sun.star.chart.LineDiagram")
	oDiagram = ChartDoc.getDiagram()
	aSize = oDiagram.getSize()
	aSize.Width = 10620
	aSize.Height = 15100 '  was 8660
	oDiagram.Size = aSize
	dim myDashes0 as New com.sun.star.drawing.LineDash
	With myDashes0
		.Style = com.sun.star.drawing.DashStyle.ROUND
		.Dots = 4 ' 4 points
		.DotLen = 200 ' of 0,5 mm
		.Dashes = 2 ' with 2 dashes
		.Distance = 300 ' spaced by 1,5 mm
 	End With
	with oDiagram
		.meanValue = true
		.RegressionCurves = com.sun.star.chart.ChartRegressionCurveType.EXPONENTIAL
		.HasXAxisTitle = true
		.XAxisTitle.String = "Transaction Month"
		.HasYAxisTitle = true
		.YAxisTitle.String = "Rate of Exchange"
		.DataCaption = com.sun.star.chart.ChartDataCaption.NONE
'		dim myDashes0 as New com.sun.star.drawing.LineDash
'		With myDashes0
'			.Style = com.sun.star.drawing.DashStyle.ROUND
'			.Dots = 4 ' 4 points
'			.DotLen = 200 ' of 0,5 mm
'			.Dashes = 2 ' with 2 dashes
'			.Distance = 300 ' spaced by 1,5 mm
'	  	End With
		.DataRowSource = com.sun.star.chart.ChartDataRowSource.COLUMNS
		DataRowProp0 = .getDataRowProperties(0)					' GBPEUR
		with DataRowProp0
			.LineDash = myDashes0
			.LineStyle = com.sun.star.drawing.LineStyle.DASH
			.LineColor = rgb(102,63,31)
			.LineWidth = 90
		end with
	end with
I also tried it within DataRowProp0.

This is a chart, btw, not a drawing. Though I supposed that might not make a difference to the code.

Thanks for your help but if you have a chance to indicate what I am doing wrong or where that would be great.

Cheers
David
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
ThierryT
Posts: 11
Joined: Fri May 13, 2016 8:52 pm

Re: To create a custom dashed line

Post by ThierryT »

LibreOffice 5.3.2.1 x 64 and AOO 4.1.3 Windows x64
kevinzhang_PKU
Posts: 3
Joined: Thu Jul 14, 2016 8:56 am

Re: To create a custom dashed line

Post by kevinzhang_PKU »

Hi David,

Seems I met the same issue like yours. I am a Java application developer, and I use OpenOffice API( juh.jar jurt.jar ridl.jar unoil.jar unoiload.jar ) to generate an .ods file with a chart. I want change the dash style of each line in the chart, so I use the interface function from API to set the dash property, but it doesn't work. The line dash style keep unchange on mather what the Dash style datas are.

Do you have the final solution?

Thanks,
Yaokai
OpenOffice 3.3 on Linux/windows
User avatar
misitu
Posts: 104
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

Re: To create a custom dashed line

Post by misitu »

edit:
I am back in this zone and will add something when I get it to work.
"BRB"

Hello, Yaokai
I'm still looking at this but some things are interrupting me, I don't expect to do any work at all in the next 2 weeks but I will post back here if* I get it to work.
I hope to be able to help you.
Cheers
David

I think it is a matter of where you put the various declarations!

*I should have said WHEN :D
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
Post Reply