Comments (2)
@IRISHMAN04 thanks for reaching out.
You should maintain a master data set from which you filter the subsets, because if you filter from the timelinesChart.data()
getter you can't go back after toggling filters.
But if you do, and simply invoke .data(newData)
after each filter interaction (no need for .refresh()
) the component should function correctly. Please double-check that you are feeding the correct data object to the chart after each filter operation though.
Also you might want to set your own filtering interaction outside of the graph's own legend. The current legend is a simple item that wasn't designed to be interactive like this. You can hide it if you do .topMargin(0)
, and then replace it with your own above the chart.
from timelines-chart.
Thanks for the help, I'll make a seperate toggle box for it because I can't exactly do multi unit filtering with this. I did however figure out a way to get the onclicks to work so I've got that code here for anyone who wants it
/**
* Setup the legend clicks.
*
* This has to run delayed after data enters the chart so that it happens after the legend has been created
*
* @param {TimelinesChart} timelinesChart
* @param {HTMLElement} timelineDiv
*
*/
function setupClicks(timelinesChart, timelineDiv) {
const allColourSlots = timelineDiv.getElementsByClassName("color-slot");
for (const slot of allColourSlots) {
const rect = slot.getElementsByTagName("rect")[0]
const text = slot.getElementsByTagName("text")[0]
const myLambda = function () { filter_scale_unit(timelinesChart, text.innerHTML) };
rect.addEventListener("click", myLambda);
text.addEventListener("click", myLambda);
}
}
/**
* Filter the data based on the scale unit
*
* @param {TimelinesChart} timelinesChart
* @param {string} scaleUnit
*
*/
function filter_scale_unit(chart, scaleUnit) {
const oldData = chart.data();
const newData = JSON.parse(JSON.stringify(oldData));
for (let i = newData.length - 1; i >= 0; i--) {
let groupLength = 0
for (const section of newData[i]["data"]) {
for (let j = section["data"].length - 1; j >= 0; j--)
if (section["data"][j]["val"] != scaleUnit)
section["data"].splice(j, 1);
groupLength += section["data"].length
}
if (groupLength == 0)
newData.splice(i, 1)
}
chart.data(newData);
}
The linchpin for me getting this to work correctly was making text
a const, or else it would pass all my click handlers the text of the last item in my legend
from timelines-chart.
Related Issues (20)
- Duplicate labels HOT 1
- How to do Multiple Selection of Timeline Segments using Cursor Drag (click+Drag) and Handling the selection of those segments to store the info and update their UI based on our logic
- some entries appear in wrong group row HOT 2
- Feature Request for SortChrono
- Custom Tooltip with custom value. HOT 1
- Feature Request: onChartRendered
- How to use enableOverview() HOT 1
- Custom messages - changed from 2.11.5 to 2.11.8? HOT 1
- Series segments not being created on firefox HOT 3
- Coloring individual (overlapping) segments HOT 2
- "Fill" option for chart sizing HOT 1
- Set the timeline height HOT 2
- Text on Segments
- Line datetime from zero
- Blue tooltips do not disappear
- User defined group label width
- Mark the weekends on the chart
- Uncaught runtime errors; it happened sometimes (when I click for loading data quickly) HOT 3
- Resizing and moving blocks
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from timelines-chart.