-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Different colours of Bars in Gantt chart #567
Labels
Comments
@rakannimer Can you please describe, How are you displaying these different colour on bars here? I didn't find any specific code for this! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would you like to work on a fix?
Current and expected behavior
`import React from 'react';
import Chart from 'react-google-charts';
import Loader from '../../components/Loader'
function TasksChart({ dashboardTasks, reducedHeight }) {
const tasksColor = []
dashboardTasks.map(element => [
tasksColor.push({
color: element?.color,
dark: element?.color,
light: element?.color
})
])
console.log('at chart', tasksColor)
const editedDashboardTasks = dashboardTasks.map((task) => [
task.task_id,
task.task_name,
task.last_doc,
new Date(
new Date(task.start_date).getFullYear(),
new Date(task.start_date).getMonth(),
new Date(task.start_date).getDate()
),
new Date(task.end_date) > new Date(new Date().setDate(new Date().getDate() + 30)) ?
new Date(
new Date(new Date().setDate(new Date().getDate() + 30)).getFullYear(),
new Date(new Date().setDate(new Date().getDate() + 30)).getMonth(),
new Date(new Date().setDate(new Date().getDate() + 30)).getDate()
) :
new Date(
new Date(task.end_date).getFullYear(),
new Date(task.end_date).getMonth(),
new Date(task.end_date).getDate()
), 0, 0, 0
]);
return (
<div id="chart_div" style={{height:'100%'}}>
<Chart
height={'100%'}
width={'100%'}
className="chart-class"
chartType='Gantt'
loader={}
data={[
[
{ type: 'string', label: 'Task ID' },
{ type: 'string', label: 'Task Name' },
{ type: 'string', label: 'Resource' },
{ type: 'date', label: 'Start Date' },
{ type: 'date', label: 'End Date' },
{ type: 'number', label: 'Duration' },
{ type: 'number', label: 'Status' },
{ type: 'string', label: 'Dependencies' }
],
...editedDashboardTasks,
]
}
options={{
width: '100%',
height: 'auto',
gantt: {
trackHeight: reducedHeight && 40 || 80,
// innerGridTrack: {fill: '#ffffff'},
// innerGridDarkTrack: {fill: '#f5f5f5'},
palette: tasksColor,
}
}}
rootProps={{ 'data-testid': '2' }}
chartEvents={[
{
eventName: "ready",
callback: ({ chartWrapper, google }) => {
console.log('chart', google)
}
}
]}
/>
);
}
export default TasksChart;
`
The palette attribute of gantt doesn't renders the colors from tasksColor array. Only renders the first colour in array.
Reproduction
To reproduce, please run the above code!
react-google-charts version
4.0.0
Possible solution
I want my solution like this!
(https://codesandbox.io/s/hungry-kepler-iwt76o)
The text was updated successfully, but these errors were encountered: