Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">

<script src="https://code.highcharts.com/gantt/highcharts-gantt.js"></script>
<script src="https://code.highcharts.com/gantt/highcharts-gantt.js"></script>
<script src="https://code.highcharts.com/gantt/modules/draggable-points.js"></script>
<script src="https://code.highcharts.com/modules/drilldown.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>

</head>

<body>
<div id="container"></div>
<div id="container"></div>
</body>

<script src="main.js"></script>
132 changes: 112 additions & 20 deletions highcharts-api/highcharts-gantt/02-journeys-visualization/main.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,114 @@
Highcharts.ganttChart('container', {

title: {
text: 'Journeys (visualization)'
},
const day = 1000 * 60 * 60 * 24;
const dateMin = Date.UTC(2024, 0, 1),
dateMax = Date.UTC(2024, 0, 8);

series: [{
name: 'Journeys',
data: [{
name: 'Cruises',
id: 'cruises',
start: Date.UTC(2024, 0, 1),
end: Date.UTC(2024, 0, 4)
}, {
name: 'Flights',
id: 'flights',
start: Date.UTC(2024, 0, 3),
end: Date.UTC(2024, 0, 7)
}]
}]

Highcharts.ganttChart('container', {
title: {
text: 'Journeys (visualization)'
},
chart: {
events: {
load() {
// Navigator doesn't display all data on start by default...
this.series.forEach(s => s.update({}, false));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you've found the issue with Navigator not rendering the rows correctly, that's is a really nice workaround!

}
}
},
xAxis: {
units: [['day']],
labels: {
formatter: function () {
return `Day ${Math.floor((this.value - dateMin) / day) + 1}`;
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using labels.formatter there is an easier way, which automatically parses date into given format, do you know which option I'm thinking about?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably about dateTimeLabelFormats?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly!

},
navigator: {
enabled: true,
liveRedraw: false

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option doesn't exist in the API

},
plotOptions: {
series: {
dataLabels: {
enabled: true,
format: `{point.options.label}`
},
dragDrop: {
draggableX: true,
liveRedraw: false,
dragPrecisionX: day,
dragMinX: dateMin,
dragMaxX: dateMax,
}
}
},
series: [{
name: 'Journeys',
data: [{
name: 'Cruises',
id: 'cruises',
start: Date.UTC(2024, 0, 1),
end: Date.UTC(2024, 0, 4)
}, {
name: 'Norway - England',
id: 'norway-england-cruise',
parent: 'cruises',
dependency: 'cruises',
start: Date.UTC(2024, 0, 2),
end: Date.UTC(2024, 0, 3)
}, {
name: 'Flights',
id: 'flights',
start: Date.UTC(2024, 0, 3),
end: Date.UTC(2024, 0, 7)
}, {
name: 'Domestic flights',
id: 'domestic-flights',
parent: 'flights',
start: Date.UTC(2024, 0, 4),
end: Date.UTC(2024, 0, 6)
}, {
name: 'Beijing - Hong Kong',
id: 'beijing-hongkong-flight',
parent: 'domestic-flights',
dependency: ['flights', 'domestic-flights'],
start: Date.UTC(2024, 0, 4),
end: Date.UTC(2024, 0, 5)
}, {
name: 'International flights',
id: 'international-flights',
parent: 'flights',
start: Date.UTC(2024, 0, 4),
end: Date.UTC(2024, 0, 7)
}, {
name: 'Norway - Brazil',
id: 'norway-brazil-flight',
label: 'Show full adventure',
drilldown: 'norway-brazil-flight-full',
parent: 'international-flights',
dependency: ['flights', 'international-flights'],
color: 'orange',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking, but the color of this point as well as the drilldown points doesn't match the gif colors exactly. Could you please update it?

start: Date.UTC(2024, 0, 5),
end: Date.UTC(2024, 0, 8)
}]
}],
drilldown: {
series: [{
showInNavigator: true,
name: 'Norway - Brazil full',
id: 'norway-brazil-flight-full',
data: [{
name: 'Norway - Spain',
id: 'norway-spain-flight',
color: 'orange',
start: Date.UTC(2024, 0, 5),
end: Date.UTC(2024, 0, 6)
}, {
name: 'Spain - Brazil',
id: 'spain-brazil-flight',
color: 'orange',
start: Date.UTC(2024, 0, 6),
end: Date.UTC(2024, 0, 8)
}]
}]
}
});