Codename one - clickable bars in bar chart - charts

I want to implement a bar chart that has clickable bars. To create a custom bar chart I created a class that extends BarChart.
Class BarChart has a method that might be useful:
clickableAreasForPoints(java.util.List<java.lang.Float> points, java.util.List<java.lang.Double> values, float yAxisValue, int seriesIndex, int startIndex)
I would like an explanation for the parameters. The doc. is a bit confusing to me.
Parameters:
points - the array of points
values - the array of values of each point
yAxisValue - the minimum value of the y axis
seriesIndex - the index of the series to which the points belong
startIndex - the start index of the rendering points
Are "points" x values and "values" the y values?
What is startIndex exactly?
EDIT:
All my data is stored in an ArrayList where the indexes represent X values and the value at an specific index is the Y value.

I think you don't need to override that. Sorry for the bad documentation we inherited that from the AChartEngine code that we forked so I'm not familiar with that either.
The API is there for internal use and it implements the protected void seriesReleased(SeriesSelection sel) callback.
I think you should be able to override that and get a callback when a column is clicked.

Related

Mixing a line with pies or sectors

A table consists of 4 fields:
X: time values in ascending order
Y: numeric value - double
A: numeric value - int
B: numeric value - int
I need to create a line chart using the X,Y values. And at each of the x,y points also show a pie/circle representing the A,B values as follows:
The centre of the pie is the x,y point.
The diameter of the pie is calculated from the values A and B.
The pie will have 2 different coloured slices, the size of each slice is proportion to the value of A and B.
After searching the documentations of lcjs, can this be done using Lightning Charts JS? if not, how about lc.NET?
Any hints is much appriciated.
Thank you
In LightningChart JS, I don't believe there is such functionality available.
Something like this should be possible (bar instead of pie)

holoviz param and panel: how to get a slider that allows a discrete list of irregularly-spaced float values?

I am using holoviz param and panel to create a dashboard displaying gridded data on a map. I have two sliders to select grid coordinates x and y. Moving the sliders displays some data for the specified gridcell.
Right now I'm using two param.Integer objects to create the sliders with the bounds set to the dimensions of the xarray dataset containing the data. When a slider moves I grab a new slice from the dataset and update the dashboard.
I'd like my sliders to display the actual longitude and latitude coordinates, not the integer indices to the xarray dataset.
I can think of several ways to do this, but haven't gotten any of them to work.
update the displayed value on the slider to show the lat or lon. This keeps the internal slider value an integer but displays the float. I can't figure out what to update in the callback to change this value.
create sliders that display lat and lon as floats. The slider's allowed values would need to come from the list of lat and lon coordinates. The step between allowed values is not constant. So I'd need a float slider that allows, say, [74.0, 74.2, 74.5] and no other values.
Maybe (probably!) I'm just really dense but I can't quite see how to plug together the arguments to param.Number or param.Integer to make (1) or (2) happen.

Format maxLabel on axis differently than other labels

I am hoping to use a different format specifically for the top axis label on my y-axis. For example, if I have a percentage value axis, I would like to see the % symbol only on the top axis label, while the rest of the labels beneath it remain formatted as numbers without a symbol.
So far, I've been using the formatter option and have created a function that receives value and index per the ECharts docs. The example link below does what I need it to do, but does it for the bottom of the axis rather than the top. I need a way to use this same logic, but select the maximum index on the axis.
Link to example in docs:
https://echarts.apache.org/en/option.html#yAxis.axisLabel.formatter
Code from example in docs:
The if (index === 0) is the logic I'm referring to
// Use callback function; function parameters are axis index
formatter: function (value, index) {
// Formatted to be month/day; display year only in the first label
var date = new Date(value);
var texts = [(date.getMonth() + 1), date.getDate()];
if (index === 0) {
texts.unshift(date.getYear());
}
return texts.join('/');
}
Here's what I've tried:
I attempted to use the index argument to figure out the max index # in my dataset, but couldn't figure out how to do that given that the function is called once per value and includes only the data for that value.
I tried passing params to the function since that's how formatter works in the series config, but it looks like that's not possible in the axis config
One (unattractive) alternative is to use the y-axis axisName to display any symbols I want to have appended to the top label, and manually position it using padding. This probably wouldn't work because I'll also need to use the axisName separately from time to time.
A Possible Hint
This might not be possible yet, but at least behind the scenes I know ECharts is able to select the top label through the showMaxLabel option in axisLabel.
Is there a way to check if a label is the maximum label in the formatter function for an axis?

How to make the set of possible values for UISlider an open interval?

I am using a UISlider to allow a user to choose among four options. I ask the user a question of the form "how much do you like this thing?", they respond by moving the slider, and then behind the scenes I map the value of the slider to one of four elements of an array. I want the first quarter of the slider to correspond to the first element of the array, the second quarter of the slider to correspond to the second element of the array, and so on.
By default, the range of a slider is [0,1], so one natural way to do what I want is:
let index = Int(rangedSlider.value * Float(currentAnswers.count) )
assuming that rangedSlider is the name of the outlet connected to the UISlider in question, and currentAnswers is the array of answers I'm mapping to. The issue with this is that if the user moves the slider all the way to the right, that sets the value of the slider to 1, which maps to index 4 by the formula above (assuming there are four answers). I can always add an additional line of code that takes care of that case separately,
if rangedSlider.value == 1 { index = currentAnswers.count - 1 }
but I prefer a one line solution.
I can also set the max value of the slider to 0.99 in the Storyboard and stick with the first line of code I wrote, but I want to know: is there a built-in way to make the range of UISlider values an open interval? Is there a better way to get the behavior I want?
Is this any more complicated than:
let index = Int(rangedSlider.value * Float(currentAnswers.count - 1))
Or have I misunderstood the problem you're having?
That way your index will be returned as a number between 0 and 3 with 0 corresponding to the first answer and 3 corresponding to the fourth answer.

How to get the y value(s) of an NSBezierPath given any x value as input

I have an NSBezierPath which is shows a visual description of some data. As such, I not only need to see the NSBezierPath visually, I also would like to query it at any x value to determine the corresponding y value(s).
In short, I would like to use the NSBezierPath (or any BezierPath) in my view, and in my model. I want the view and the model to use the same formula, so that the visual representation of the model is accurate.
I recognize that in providing an x value, the number of corresponding y values could be zero, one, or many. Currently, I do not see any way to get individual points out of the NSBezier path, except for the control points and endpoints. I want to be able to query the Bezier Path for its value at ANY location, not just critical points.