[Solved] Possible to program Line Properties in Chart?

Keyboard macros or custom scripts

[Solved] Possible to program Line Properties in Chart?

Postby misitu » Tue Jun 21, 2016 3:19 am

I have a line chart with a decent smooth curve option.
It displays 2 data columns as separate lines (against an X axis by Date).

I thought it would be useful to be able to change the line colours and make dashes and dots.

However, I can't see any way of linking the Data Source to a set of modifiable Line Properties.

For example
range = a2:c13
column A is Date Logged (X axis)
column B is curve 1 (data source 1) (Y axis)
column C is curve 2 (data source 2) (Y axis)
Both B and C are Foreign Exchange Rates. The idea is to see how well one data source tracks the other.

I have a solid blue line for curve 1 and a solid red line for curve 2. It would be ideal, for the sake of presentation, if they could be made dashed or dotted.

How can I tell Charts that the line for Data Source 1 has to have "These" Line Properties, and that for Data Source 2 "Some Other" Properties?

Or is this not possible in macros?

Thanks in advance
David

Referring, if necessary, or for curiosity, to this earlier Post which has more detail but I marked it "Solved" because it was asking too high a level question to be useful and probably causing a bit of wasted time that way.
Last edited by misitu on Tue Jun 21, 2016 3:28 pm, edited 1 time in total.
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
User avatar
misitu
 
Posts: 89
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

Re: Is It Possible to program Line Properties in Chart?

Postby FJCC » Tue Jun 21, 2016 5:40 am

This code works but it seems to have a problem when used more than once. The second data series, the one whose properties get modified, doesn't get plotted the second time and I haven't found a consistent way to fix that. I hope it gets you started on modifying line properties.
Code: Select all   Expand viewCollapse view
Dim Rect As New com.sun.star.awt.Rectangle
Dim RangeAddress(0) As New com.sun.star.table.CellRangeAddress

Rect.X = 8000
Rect.Y = 1000
Rect.Width = 25000
Rect.Height = 10000
RangeAddress(0).Sheet = 0
RangeAddress(0).StartColumn = 0
RangeAddress(0).StartRow = 0
RangeAddress(0).EndColumn = 2
RangeAddress(0).EndRow = 12

Charts = ThisComponent.Sheets(1).Charts
'charts.removeByName("MyChart")
Charts.addNewByName("MyChart", Rect, RangeAddress(), True, True)
Chart = Charts.getByName("MyChart").EmbeddedObject
Chart.Diagram = Chart.createInstance("com.sun.star.chart.LineDiagram")
DataRowProp1 = Chart.Diagram.getDataRowProperties(1)
DataRowProp1.LineStyle = com.sun.star.drawing.LineStyle.DASH
DataRowProp1.LineDashName = "Fine Dashed"
DataRowProp1.LineColor = RGB(100,100,100)
DataRowProp1.LineWidth = 120
AOO 3.4 or 4.1 on MS Windows XP ( before 2013-08-03) or Windows 7
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 6747
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Is It Possible to program Line Properties in Chart?

Postby misitu » Tue Jun 21, 2016 1:06 pm

Thanks! I will follow that up.
I had recently and accidentally burrowed into a page I hadn't found earlier about Data Row Properties and was going to start work on that. Your example has given me a step forward.
Best regards, David
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
User avatar
misitu
 
Posts: 89
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

Re: Is It Possible to program Line Properties in Chart?

Postby misitu » Tue Jun 21, 2016 1:41 pm

A great help, FJCC.

I might have got there in another week! I didn't have a clue how to tie up the "data source" with its line properties.

I have a few more tasks that this is going to accelerate.

After
Code: Select all   Expand viewCollapse view
ChartDoc.Diagram = ChartDoc.createInstance("com.sun.star.chart.LineDiagram") 'add copy of chart with B-spline Resolution 6 Polynomials
oDiagram = ChartDoc.getDiagram()
with oDiagram
   .HasXAxisTitle = true
   .XAxisTitle.String = "Transaction Month"
   .HasYAxisTitle = true
   .YAxisTitle.String = "Rate of Exchange"
   .DataCaption = com.sun.star.chart.ChartDataCaption.NONE
   .DataRowSource = com.sun.star.chart.ChartDataRowSource.COLUMNS


I added

Code: Select all   Expand viewCollapse view
   DataRowProp0 = .getDataRowProperties(0)
   with DataRowProp0
      .LineStyle = com.sun.star.drawing.LineStyle.DASH
      .LineDashName = "Fine Dashed"
      .LineColor = RGB(100,0,0)
      .LineWidth = 50
   end with   
   DataRowProp1 = .getDataRowProperties(1)
   with DataRowProp1
      .LineStyle = com.sun.star.drawing.LineStyle.DASH
      .LineDashName = "Fine Dotted"
      .LineColor = RGB(100,100,100)
      .LineWidth = 120
   end with


with thanks and appreciation of your time taken to help
Best regards
David
Attachments
Calc Chart Macro, how to generate lines with different properties.jpg
To demonstrate that the above code works!
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
User avatar
misitu
 
Posts: 89
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 4 guests