In dc.js I'm displaying the number of filtered and total rows with dc.dataCount:
dc.dataCount(".dc-data-count", "charts")
.dimension(data_cf)
.group(all);
and
<div class="dc-data-count">
<strong class="filter-count"></strong> selected out of <strong class="total-count"></strong> records
On the same page, I have a d3 donut chart that I've drawn. Within this chart I'd like to display the filter-count (which updates as filters are applied), as well as other calculations like the sum of a value in the current selection. Given that dc.dataCount is accessed by a div class, I don't know how to access the number to place precisely in my donut chart.
How can I pass values from dc.dataCount or some other grouping into a d3 object?
Thanks!
I would do this with a renderlet on the donut chart that just reads the values you need, and adds them. Renderlets run after the chart has rendered, so there is a slight delay, but it shouldn't be too disturbing for this use.
As for how to get the numbers, there is no magic to the dataCount widget; it's just reading crossfilter values:
https://github.com/dc-js/dc.js/blob/master/src/data-count.js#L77
So you can add text elements to the svg using dimension.size() and group.value() in the same way.
Related
I have two tables, one that shows the sales history of salespeople per year, and another table that shows the sales history in months. As you can see in the image below:
I need to create a composite chart (I believe it is a composite chart, as it will have more than 01 line) that is exactly the representation of the month table.
After creating the chart when I click on the seller Miguel for example, the chart will be rendered with the history of that seller.
And for example if I click on month 03 of the graph, the table of sellers will be rendered only with the sales that were made in month 03.
I don't know how to do it, I managed to create a composite chart that presents the same data as the month table, however, I was unable to integrate my chart together with my tables.
Can you tell me how I can do that?
I put the codes I made in JSFiddle, here are the links:
Sales/Month Table: https://jsfiddle.net/bernalvinicius/ejxcfpvz/15/
Month Chart: https://jsfiddle.net/bernalvinicius/kanm158j/17/
Thanks in advance.
Just put all your code in the same file(s), combine your crossfilter instances, and put all the charts in the same chart group (the default), and it should work fine.
The chart group is the second parameter to each chart constructor. If it's not specified, then the chart goes into the default chart group.
When any chart is filtered in a chart group, it will tell all the other charts in that chart group to redraw, and they will pull their new data from their respective crossfilter groups. (Sorry about the naming, a dc.js chart group has nothing to do with a crossfilter group.)
In order to combine your code, I renamed both of the crossfilter instances to cf. Then I added the new fields you are generating to the existing rows, instead of mapping the data:
data.forEach(d =>
Object.assign(d, {
mes: d.Month,
atual: d.Vendas_Ano,
passado: d.Vendas_Ant
})
);
In your table fiddle, you were initializing the table for every row in the data with a data.forEach() which wasn't necessary. That's why it was so slow to load.
Other than that, both fiddles had the same general structure so I just copied and pasted the code from the table fiddle to the composite fiddle, HTML, JS, and CSS.
In the JS I made sure to put the same lines outside and inside the d3.json() callback as before.
It looks like it works?
https://jsfiddle.net/gordonwoodhull/0q1y5ftr/15/
So for a while I had struggled with how to filter a dataTable in dc.js without affecting other dimensions. This seems counter-intuitive, as it goes against what crossfilter(the data filter behind dc.js) does best, but I'll explain why this can be relevant.
Suppose I have a dataset of peoples name age and gender. In one of my datatables, I only want to display males; using one crossfilter, I would be forced to filter all my other datatables by males.
Suppose I also have a pie chart that lists the first letter of each person's name, and I want to be able to filter on the 'M's. I have a table for males, and a table for females. I don't want these tables to affect the distribution of the pie chart, but I want to be able to click on the pie chart and have it filter the dc.js datatables. More or a less a one way filter.
What is the way to achieve this?
dc.js datatables accept crossfilter dimensions. I got around the problem by extending the dimension as follows.
function preFilter(dim,okey,oval){
return{
top:function(x){
var a1 = dim.top(x).filter(function(v){
return v[okey] === oval;
});
return a1;
}
};
}
This worked well for me, I hope it can help others.
My requirement is to draw 3 charts in a row and break the row after that for next sequence of charts
There are multiple ways to do this using BIRT Designer:
Add a grid and put a chart into each cell
Add a table, group the contents, put a chart in the group footer, hide the details rows
Add a crosstab, change the aggregated totals to charts and hide whatever content you want hidden
Use dynamic text, HTML, and the JavaScript API to display the charts in divs
Organize your grouping or crosstab dimensions to be in sets of 3.
A,100
B,120
C,50
D,20
Plotting this in a Chart produces the correct result: it gives me a chart with 4 columns.
What i want however is to add all these values into one column and have the chart show only one as i will be adding more data series (via lookUp) that will show additional related data.
Can this be achieved?
You can modify the dataset of the report, by summing A,B,C and D instead of selecting each one on it's own.
Try changing the chart type to a stacked column chart
In my application I have used jQuery Highcharts for reports.
In Highcharts, how can I sort the legend items? Means when I click on legend items, it should sort active items on top and hide items at the bottom automatically. Because I have more than 50 legend items in list. plugin has provided the pagination also. but if I active the bottom portion of the items, it will be remains at the bottom. we can't able to find out which items are active.
Is there any function or logic to sort items in legend?
It's not supported. You need to loop through all series and points and then update each series using series.update({ legendIndex: sortedIndex }) function.