Anyone Produced A Gnatt Chart #1273
Unanswered
MarkWildey
asked this question in
Q&A
Replies: 1 comment
-
|
Sorry for the late reply. The PR #2294 just fixed panic on add chart with no fill series, this patch will be released on next version, please upgrade master branch code by
package main
import (
"fmt"
"time"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
defer func() {
if err := f.Close(); err != nil {
fmt.Println(err)
}
}()
for r, row := range [][]interface{}{
{"Task", "Start Date", "Days"},
{"Task 1", time.Date(2025, 6, 1, 0, 0, 0, 0, time.UTC), 5},
{"Task 2", time.Date(2025, 6, 6, 0, 0, 0, 0, time.UTC), 3},
{"Task 3", time.Date(2025, 6, 12, 0, 0, 0, 0, time.UTC), 2},
{"Task 4", time.Date(2025, 6, 20, 0, 0, 0, 0, time.UTC), 2},
{"Task 5", time.Date(2025, 6, 26, 0, 0, 0, 0, time.UTC), 4},
{"Task 6", time.Date(2025, 7, 4, 0, 0, 0, 0, time.UTC), 4},
{"Task 7", time.Date(2025, 7, 12, 0, 0, 0, 0, time.UTC), 2},
} {
cell, err := excelize.CoordinatesToCellName(1, r+1)
if err != nil {
fmt.Println(err)
return
}
if err := f.SetSheetRow("Sheet1", cell, &row); err != nil {
fmt.Println(err)
return
}
}
min := 45809.0
if err := f.AddChart("Sheet1", "E2", &excelize.Chart{
Type: excelize.BarStacked,
Series: []excelize.ChartSeries{
{
Name: "Sheet1!$B$1",
Categories: "Sheet1!$A$2:$A$8",
Values: "Sheet1!$B$2:$B$8",
Fill: excelize.Fill{Type: "pattern", Pattern: 0},
},
{
Name: "Sheet1!$C$1",
Categories: "Sheet1!$A$2:$A$8",
Values: "Sheet1!$C$2:$C$8",
},
},
XAxis: excelize.ChartAxis{ReverseOrder: true},
YAxis: excelize.ChartAxis{
Minimum: &min, NumFmt: excelize.ChartNumFmt{CustomNumFmt: "m/d"},
},
Title: excelize.ChartTitle{
Paragraph: []excelize.RichTextRun{{Text: "Gantt Chart"}},
},
Legend: excelize.ChartLegend{Position: "none"},
}); err != nil {
fmt.Println(err)
return
}
if err := f.SaveAs("Book1.xlsx"); err != nil {
fmt.Println(err)
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
I'm looking to produce a Gnatt chart which I guess will come out as a Stacked Bar Chart.
In issue #213 there was a request to control the colors of each bar, which still seems to be open. For a Gnatt chart, I would like to set one or more of the stacked bars to clear/no color to simulate a timeline for various events.
If anyone has any code to produce a Gantt chart I'd sure welcome some guidance.
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions