Filter a chart directly in libreoffice calc - filter

I have a chart which shows the data I want when I filter for values > 0 on a single column. But I would like to have this filter inside of the chart itself so that I can look at the workbook with no filters, and still see the chart with the zero values filtered out.
So I want the first row to appear in the chart because the last value is > 0, but I want the chart to ignore the 2nd row because the last column value == 0
Is there some way to set a filter on the chart itself?

Related

Tooltip with Multi-Series Line Chart in Vega-Lite API

I am trying to recreate this example in Vega-Lite API in an Observable notebook. I am able to recreate the ruler with the multiple line series from another example in Observable. But I am having trouble adding tooltips, I would like to add the symbol ticker and the price of the stock. Here is my Observable notebook. Where would I put the tooltip specifications? Thanks!
plot = {
// select a point for which to provide details-on-demand
const hover = vl.selectSingle()
.encodings('x') // limit selection to x-axis value
.on('mouseover') // select on mouseover events
.nearest(true) // select data point nearest the cursor
.empty('none'); // empty selection includes no data points
// define our base line chart
const line = vl.markLine()
.data(stocks)
.encode(
vl.x().fieldT('date'),
vl.y().fieldQ('price'),
vl.color().fieldN('symbol'),
);
// shared base for new layers, filtered to hover selection
const base = line.transform(vl.filter(hover));
return vl.data(stocks)
.layer(
line,
// add a rule mark to serve as a guide line
vl.markRule({color:'#c0c0c0'})
.transform(
vl.filter(hover),
vl.pivot({pivot: 'symbol', value: 'price', groupby: ['date']}))
.encode(vl.x().fieldT('date'),
vl.tooltip().fieldQ('price')),
// add circle marks for selected time points, hide unselected points
line.markCircle()
.select(hover) // use as anchor points for selection
.encode(vl.opacity().if(hover, vl.value(1)).value(0),
vl.tooltip(['symbol','price']))
)
.render(); }
Here's how you use pivot on that example
vl.pivot('symbol').value('price').groupby( ['date']))
The pivot there helps you getting the data into table format, so you can have all the symbol prices available in one row. Here is a full working example of a Vega-Lite API multi-line series chart with tooltips:
https://observablehq.com/#vega/multi-series-line-chart-with-tooltip

Filter list for many pie charts and removing them

I've got 2 pie charts with data like:
data: [
{diseaseType: 'Cancer', diseaseDetails: 'Lung cancer', quantity: 100},
{diseaseType: 'Diebetes', diseaseDetails: 'Unspecific', quantity: 650},
{diseaseType: 'Cancer', diseaseDetails: 'Breast cancer', quantity: 80}
]
i'm tying to get list of filters and able to remove them by user like (it's only controlled test code):
this.diseasePieChart.filters().splice(0, 1)
dc.renderAll()
it's updating first chart, but second (connected with first) not, it's stay like it was before remove filter.
Second chart i'm rendering like this:
self.diseasePieChart.on('filtered.monitor', function (chart) {
// create dimensions etc and render second chart
}
I also tried to do again crossfilter(data) after filter remove. When i'm calling dc.filterAll all filters are reset.
thanks for any help !
The correct entry points for changing filters are chart.filter() or chart.replaceFilter(), depending on whether you are trying to toggle individual items or change the entire array of filters at once.
As you found out, manipulating the array of filters inside the chart might affect the way the chart draws, but it won't convey the change to the crossfilter dimension and the other charts.
Note that as documented in the link above, the accepted type for the parameter for each of these functions is a little surprising:
The filter parameter can take one of these forms:
A single value: the value will be toggled (added if it is not present in the current filters, removed if it is present)
An array containing a single array of values ([[value,value,value]]): each value is toggled
When appropriate for the chart, a dc filter object such as
dc.filters.RangedFilter for the dc.coordinateGridMixin charts
dc.filters.TwoDimensionalFilter for the heat map
dc.filters.RangedTwoDimensionalFilter for the scatter plot
null: the filter will be reset using the resetFilterHandler
So if you want to get the array, remove an item, and then set it back, you could either:
var filters = chart.filters().slice(0); // copy the array of filters
filters.splice(0,1)
chart.replaceFilter([filters])
.redrawGroup();
or (using the toggle feature):
chart.filter(chart.filters()[0])
.redrawGroup();
Note that you usually want to redraw, not render, after changing a filter. This will allow the animated transitions to display, and is a little bit quicker.
Also, chart.redrawGroup is the same as dc.redrawAll() but it's a little safer in case you have more chart groups in the future.

D3js - filter column from csv

I have a boxplot which is part of a Dashboard. The boxplot is based on this example. What I want is that the corresponding bar from the boxplot is highlighted when the user selects an element from another graphic of the dashboard (and the other way around). How can I just select one element from the boxplot? Until now I did the filtering by using e.g
svg.selectAll(".box").filter(function(d) { return d.name == "name1" })
But in this case I filtered a row from the csv and now I need to filter a column ... I don't understand how to do this.

Get value of column in dataset in javascript

I would like to draw dynamic vertical marker line in my chart. Position of marker is available in dataset named ml_data in column ml_position. This is a dataset with one row and one column only. Is there a way how I can get value of ml_position in javascript? Currently I have the following working example:
function beforeDrawMarkerLine(axis, markerLine, icsc)
{
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
var ml_value = 20;
markerLine.setValue(NumberDataElementImpl.create(ml_value)) ;
}
The value is currently fixed (20). I would like to assign value of ml_position to ml_value.
My working solution:
Create global variable "mpos" and put your chart into simple table with one row a one column. Assign dataset with ml_position to table. This is important for executing dataset onFetch script before rendering chart. Finally set following scripts:
Dataset onFetch script:
reportContext.setPersistentGlobalVariable("mpos",row["ml_position"].toString());
Chart onRender script:
function beforeDrawMarkerLine(axis, markerLine, icsc)
{
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
var ci = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("mpos");
markerLine.setValue(NumberDataElementImpl.create(ci)) ;
}

Tablix column formatting values

I have a tablix with several columns. One of columns has discount percentage values. I want to change the font to white if all of the rows have value 0, and if some of the cells have different value, I want all the values to apperar black.
I have set the Font Color value to:
=IIF(SUM(Fields!Discount.Value)=0, "White", "Black")
When all columns are 0, everything shows up white.
The problem is when some of the values are not 0, they show up black, but the 0 values are white and there are empty cells.
If you're using this expression in the detail row of the Tablix, you might need to add a Scope paremeter to your Sum clause, something like:
=IIF(SUM(Fields!Discount.Value, "DataSet1")=0, "White", "Black")
This is because the Sum will execute in the current Scope unless another is specified, so your expression will only consider the current row. Adding the scope as above will consider all rows in the Dataset.

Resources