How to add a dynamic marker to a BIRT chart - charts

I have created a BIRT report with a chart which gets data from a oracle database.
I got the chart done properly. Now i need to add 4-5 markers to the chart.
Values for markers which could be changed are also stored in a database.
I tried the scripts mentioned in this article with some modifications http://blogs.actuate.com/birt-chart-scripting-dynamic-markers/
function beforeGeneration(chart, icsc)
{
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.attribute);
importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);
var chart = icsc.getChartInstance();
var yAxis = chart.getBaseAxes()[0];
var min_value = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("min_val");
var ok_value = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("ok_val");
var great_value = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("great_val");
min_ml = MarkerLineImpl.create(yAxis, NumberDataElementImpl.create(min_value));
min_ml.getLabel().getCaption().setValue("Minimum");
min_ml.getLineAttributes().getColor().set(255,0,0);
}
It generates a marker but at the wrong location.
Seems like it doesn't properly get marked according to the x axis values.
What could be the issue in this script?

I have found the issue with the script.
I tried giving a hard coded value to the min_value then it worked. After debugging i found out that the data format of the X axis was with decimals which didn't match with the integer format value taken from the database.
From the format chart window i changed the axis data format to a number with 0 decimals.Then it worked :)

Related

LO Calc Basic - What is the right property name for the axis major/minor settings and how to set them correctly?

Using a libreoffice basic macro for charts, we can control the maximum value of an axis and turn the automatic mode on/off:
oAxis.AutoMax = False
oAxis.Max = 12345
But what are the right property names for
Major Interval
Major Auto
Major Time
which you can set manually
???
First, I created a chart with Insert Chart > Line > Points and Lines.
Modifying the Y axis with code was fairly straightforward.
For both axes, I went into formatting and specified Positioning > Interval Marks > Minor > Outer so that the minor ticks are shown.
oCharts = ThisComponent.getSheets().getByIndex(0).getCharts()
oEmbeddedObject = oCharts.getByIndex(0).getEmbeddedObject()
oDiagram = oEmbeddedObject.getDiagram()
oYAxis = oDiagram.getYAxis()
oYAxis.StepMain = 40.0
oYAxis.StepHelpCount = 3
Here is what the Y Axis properties looked like after running the code:
AutoStepMain (and the corresponding Major interval checkbox) started out as True, but setting the StepMain value via macro changed it to False.
With the X axis, things were more complex. For the scale, there was a choice of Type, and selecting Date seemed to be the only way to control step settings.
After that, instead of StepMain (which didn't seem to be relevant in this case), there is a complex structure called ExplicitTimeIncrement that specifies the type of increment (Days or Months) along with each value. I didn't dig too far into it, but it looks like it has all of the values you were asking about.
EDIT:
I tried the following code, but none of the values were changed, and the last line throws an error stating that the property is read-only (as also shown by MRI). So perhaps the values cannot be modified via the API.
sTimeIntervalMajor = CreateUnoStruct("com.sun.star.chart.TimeInterval")
sTimeIntervalMajor.Number = 4
sTimeIntervalMajor.TimeUnit = 0
sTimeIntervalMinor = CreateUnoStruct("com.sun.star.chart.TimeInterval")
sTimeIntervalMinor.Number = 1
sTimeIntervalMinor.TimeUnit = 0
sTimeIncrement = CreateUnoStruct("com.sun.star.chart.TimeIncrement")
sTimeIncrement.MajorTimeInterval = sTimeIntervalMajor
sTimeIncrement.MinorTimeInterval = sTimeIntervalMinor
sTimeIncrement.TimeResolution = 1
oXAxis = oDiagram.getXAxis()
oXAxis.ExplicitTimeIncrement.MajorTimeInterval = sTimeIntervalMajor
oXAxis.setPropertyValue("ExplicitTimeIncrement", sTimeIncrement)
oXAxis.ExplicitTimeIncrement = sTimeIncrement
It might also be worth posting at ask.libreoffice.org or forum.openoffice.org to see if anyone there can find a way to modify the values, with a link to this question.
Of course, the UNO API isn't the only possibility. You could write a script to unzip the .ods file and modify the XML code with a parsing library such as xml.etree or regular expressions.

Cast constant value from series

I'm completely new to this forum and tradingview/pinescript. I am trying to script an indicator, and part of the script requires assigning a constant value to a variable from a series.
From a moving average of the volume (50day average volume), I want to set the constant variable 'reference_Vol' to the value of the moving average from yesterday's price bar only and no other days in the past before yesterday, but the variable gets overwritten after each older bar as 'volume' is a series, so effectively the variable is not constant but dynamically changes over the history of the price bars.
SMA_50d = sma(volume,50)
reference_Vol =SMA_50d[1]
I have tried setting the value as a literal (literal int(x)), messing around with the valuewhen() function, but I have just not enough scripting experience of what I am doing. I have a feeling there is an easy solution to this, and I could really use some help.
Thanks a bunch!
This should do what you intended
//#version=5
indicator("My Script", overlay=false)
var float reference_Vol = na
new_day = ta.change(dayofmonth)
SMA_50d = ta.sma(volume,50)
if new_day
reference_Vol := SMA_50d[1]
plot(reference_Vol, style=plot.style_linebr, color=new_day ? na : color.blue)

Set new column definition by setColumnDefs doesn't work anymore

I'm trying to set new column definitions by calling setColumnDefs using the grid API. This doesn't work as expected. The names of the column headers will not be updated anymore!
See this Plunkr: Version 19.1.x
Version 19.0.0 is latest working version.
See this Plunkr: Version 19.0.0
For me it seems to be a bug!?
In my project I'm using Angular 5 and I notice the same behaviour.
I was able to reproduce your behaviour. The following (dirty) workaround works:
gridOptions.api.setColumnDefs([]);
gridOptions.api.setColumnDefs(newColDefs);
Setting the columnDefs to an empty array and then passing the newColDefs seems to achieve what you are looking for.
I suppose it up to the new way of change-detection on the latest version.
If you will update your code like that:
function updateColDef()
{
let data = [];
columnDefs.forEach(function(colDef) {
colDef.headerName = colDef.headerName + ' X ';
data.push(colDef);
})
data.push( {
headerName: 'New Column',
});
gridOptions.api.setColumnDefs(data);
}
It will work as expected.
Update:
When new columns are set, the grid will compare with current columns and work out which columns are old (to be removed), new (new columns created) or kept (columns that remain will keep their state including position, filter and sort).
Comparison of column definitions is done on 1) object reference comparison and 2) column ID eg colDef.colId. If either the object reference matches, or the column ID matches, then the grid treats the columns as the same column.
In the first case, it was an object comparison, on the second sample (after update) its colId case.
changes came from 19.1 version release
AG-1591 Allow Delta Changes to Column Definitions.

Ext js4 gauge chart and setValue

I'm trying to setup a gauge chart in extjs 4 that should be feeded from a "static" value calculated from data.Store data.
The calculated data is obtained in a datachange listener in the store.
I read about the setValue method but i really did not understand how to use it, can anyone give me some hint?
Thanks to all,
N
After banging my head to the wall for some hours, I just found out how it works. And it was oh so obvious:
// the value that you want to set up
var newValue = 35;
// a reference to the chart
var chart = Ext.getCmp('myChartId');
// setting the value
chart.series.items[0].setValue(newValue)
Notice that setValue is within chart.series.items[0]. This is because, as conter-intuitive as it may sound, Gauge is NOT a type of chart but a type of series.
Hope this helps other newbies of Ext like me, because the documentation could really use some more examples!

Error caused by string being too big when passed to Google Visualization API

I am trying to create a WordCloud through the Google Visualization API. You have to create a google.visualization.DataTable and add the string to a cell in the table. I basically copied the example linked above, and passed in a simple string of a few words (#note.articletext), and the WordCloud worked fine.
<script type="text/javascript">
google.load("visualization", "1");
google.setOnLoadCallback(draw);
function draw() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Text1');
data.addRows(1);
data.setCell(0, 0, '<%= #note.articletext %>');
var outputDiv = document.getElementById('wcdiv');
var wc = new WordCloud(outputDiv);
wc.draw(data, {width:300, height:300});
}
</script>
But I want to create the WordCloud based on a article, which (obviously) is a very large string. When I pass in a string containing a whole article, I get the following error:
unterminated string literal
data.setCell(0, 0, 'There was a da...ne ended with a time-out in his crib.
Again, this error doesn't occur when I pass in a small string, so it's caused by the size of the string. Or potentially the google.visualization.DataTable has a limit on how big a single cell can be (I can't find mention of such a limit though). Does anyone know how can I fix this? Thanks for reading.
Edit: In case it's important, I'm using Ruby on Rails.
The text you are adding to the datacell most likely spans multiple lines causing the 'unterminated string literal' error.
Try parsing the text and put it all on one line. Or add cells on a line by line basis.