Skip to content

When creating a graph with the AddChart function, drawing1.xml(chart1.xml) gets corrupted if the comparison target is 7 or more. #422

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

Closed
GinSanaduki opened this issue Jun 8, 2019 · 2 comments
Labels
confirmed This issue can be reproduced

Comments

@GinSanaduki
Copy link

GinSanaduki commented Jun 8, 2019

Book_06.xlsx
Book_07.xlsx

When there are six types of comparison targets...

// test01.go
package main

import (
    "fmt"

    "github.com/360EntSecGroup-Skylar/excelize"
)

func main() {
    categories := map[string]string{"A2": "SS", "A3": "S", "A4": "M", "A5": "L", "A6": "LL", "A7": "XL", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
    values := map[string]int{"B2": 2, "C2": 3, "D2": 3, "B3": 5, "C3": 2, "D3": 4, "B4": 6, "C4": 7, "D4": 8, "B5": 6, "C5": 7, "D5": 8, "B6": 6, "C6": 7, "D6": 8, "B7": 6, "C7": 7, "D7": 8}
    f := excelize.NewFile()
    for k, v := range categories {
        f.SetCellValue("Sheet1", k, v)
    }
    for k, v := range values {
        f.SetCellValue("Sheet1", k, v)
    }

    f.AddChart("Sheet1", "E1", `{"type":"line","series":[{"name":"Sheet1!$A$2","categories":"","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"},{"name":"Sheet1!$A$5","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"},{"name":"Sheet1!$A$6","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"},{"name":"Sheet1!$A$7","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"top","show_legend_key":false},"title":{"name":"Fruit Line Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero"}`)
    err := f.SaveAs("./Book_06.xlsx")
    if err != nil {
        fmt.Println(err)
    }

}

test01

When there are seven types of comparison targets...
Of course, also in the case of eight or more, with the same result.

// test02.go
package main

import (
    "fmt"

    "github.com/360EntSecGroup-Skylar/excelize"
)

func main() {
    categories := map[string]string{"A2": "SS", "A3": "S", "A4": "M", "A5": "L", "A6": "LL", "A7": "XL",  "A8": "XLL", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
    values := map[string]int{"B2": 2, "C2": 3, "D2": 3, "B3": 5, "C3": 2, "D3": 4, "B4": 6, "C4": 7, "D4": 8, "B5": 6, "C5": 7, "D5": 8, "B6": 6, "C6": 7, "D6": 8, "B7": 6, "C7": 7, "D7": 8, "B8": 6, "C8": 7, "D8": 8}
    f := excelize.NewFile()
    for k, v := range categories {
        f.SetCellValue("Sheet1", k, v)
    }
    for k, v := range values {
        f.SetCellValue("Sheet1", k, v)
    }

    f.AddChart("Sheet1", "E1", `{"type":"line","series":[{"name":"Sheet1!$A$2","categories":"","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"},{"name":"Sheet1!$A$5","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"},{"name":"Sheet1!$A$6","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"},{"name":"Sheet1!$A$7","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"},{"name":"Sheet1!$A$8","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"top","show_legend_key":false},"title":{"name":"Fruit Line Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero"}`)
    err := f.SaveAs("./Book_07.xlsx")
    if err != nil {
        fmt.Println(err)
    }
}

test02

When the drawing1.xml of Book_06.xlsx and the drawing1.xml of Book_07.xlsx were compared, there was no difference in the file contents.
Even when there were five types of comparison targets, there were no differences in drawing1.xml.
Basically, drawing1.xml does not change with the number of comparison target, so it seems that a problem will occur in the part that refers to drawing1.xml.

test03

When the chart1.xml of Book_06.xlsx and the chart1.xml of Book_07.xlsx were compared, chart1.xml of Book_07.xlsx caught the following part...

</c:strRef></c:cat><c:val><c:numRef><c:f>Sheet1!$B$4:$D$4</c:f></c:numRef></c:val></c:ser><c:ser><c:idx val="6"></c:idx><c:order val="6"></c:order><c:tx><c:strRef><c:f>Sheet1!$A$8</c:f></c:strRef></c:tx><c:spPr><a:ln cap="rnd" w="25400"><a:solidFill><a:schemeClr val="accent7"></a:schemeClr></a:solidFill></a:ln></c:spPr><c:dLbls><c:showLegendKey val="false"></c:showLegendKey><c:showVal val="true"></c:showVal><c:showCatName val="false"></c:showCatName><c:showSerName val="true"></c:showSerName><c:showPercent val="true"></c:showPercent><c:showBubbleSize val="true"></c:showBubbleSize><c:showLeaderLines val="false"></c:showLeaderLines></c:dLbls><c:cat><c:strRef><c:f>Sheet1!$B$1:$D$1</c:f></c:strRef></c:cat><c:val><c:numRef><c:f>Sheet1!$B$4:$D$4</c:f></c:numRef></c:val></c:ser><c:dLbls><c:showLegendKey val="false"></c:showLegendKey><c:showVal val="true"></c:showVal><c:showCatName val="false"></c:showCatName><c:showSerName val="true"></c:showSerName><c:showPercent val="true"></c:showPercent><c:showBubbleSize val="true"></c:showBubbleSize><c:showLeaderLines val="false"></c:showLeaderLines></c:dLbls>

・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・

In the argument contents of line 470 of chart.go "f.addChart (formatSet)", the component "cap" of Series changes from "len: 6, cap: 6" to "len: 7, cap: 9" to being caught.

test01.go
When there are six types of comparison targets...

github.com/360EntSecGroup-Skylar/excelize.(File).AddChart() C:/Go/src/github.com/360EntSecGroup-Skylar/excelize/chart.go:470 (PC: 0x5544a5)
465: drawingRID := f.addDrawingRelationships(drawingID, SourceRelationshipChart, "../charts/chart"+strconv.Itoa(chartID)+".xml", "")
466: err = f.addDrawingChart(sheet, drawingXML, cell, formatSet.Dimension.Width, formatSet.Dimension.Height, drawingRID, &formatSet.Format)
467: if err != nil {
468: return err
469: }
=> 470: f.addChart(formatSet)
471: f.addContentTypePart(chartID, "chart")
472: f.addContentTypePart(drawingID, "drawings")
473: return err
474: }
475:
(dlv) p formatSet
github.com/360EntSecGroup-Skylar/excelize.formatChart {
Type: "line",
Series: []github.com/360EntSecGroup-Skylar/excelize.formatChartSeries len: 6, cap: 6, [
(
"github.com/360EntSecGroup-Skylar/excelize.formatChartSeries")(0xc000114800),
(
"github.com/360EntSecGroup-Skylar/excelize.formatChartSeries")(0xc000114898),
("github.com/360EntSecGroup-Skylar/excelize.formatChartSeries")(0xc000114930),
(
"github.com/360EntSecGroup-Skylar/excelize.formatChartSeries")(0xc0001149c8),
("github.com/360EntSecGroup-Skylar/excelize.formatChartSeries")(0xc000114a60),
(
"github.com/360EntSecGroup-Skylar/excelize.formatChartSeries")(0xc000114af8),
],
Format: github.com/360EntSecGroup-Skylar/excelize.formatPicture {FPrintsWithSheet: true, FLocksWithSheet: false, NoChangeAspect: false, OffsetX: 15, OffsetY: 10, XScale: 1, YScale: 1, Hyperlink: "", HyperlinkType: "", Positioning: ""},
Dimension: github.com/360EntSecGroup-Skylar/excelize.formatChartDimension {Width: 480, Height: 290},
Legend: github.com/360EntSecGroup-Skylar/excelize.formatChartLegend {
None: false,
DeleteSeries: []int len: 0, cap: 0, nil,
Font: ("github.com/360EntSecGroup-Skylar/excelize.formatFont")(0xc0001144b0),
Layout: (
"github.com/360EntSecGroup-Skylar/excelize.formatLayout")(0xc0001144f0),
Position: "top",
ShowLegendEntry: false,
ShowLegendKey: false,},
Title: github.com/360EntSecGroup-Skylar/excelize.formatChartTitle {
None: false,
Name: "Fruit Line Chart",
Overlay: false,
Layout: (*"github.com/360EntSecGroup-Skylar/excelize.formatLayout")(0xc000114548),},
XAxis: github.com/360EntSecGroup-Skylar/excelize.formatChartAxis {
Crossing: "",
MajorTickMark: "",
MinorTickMark: "",
MinorUnitType: "",
MajorUnit: 0,
MajorUnitType: "",
DisplayUnits: "",
DisplayUnitsVisible: false,
DateAxis: false,
ReverseOrder: false,
Maximum: 0,
Minimum: 0,
NumFormat: "",
NumFont: (struct { Color string "json:"color""; Bold bool "json:"bold""; Italic bool "json:"italic""; Underline bool "json:"underline"" })(0xc0001145f8),
NameLayout: (
"github.com/360EntSecGroup-Skylar/excelize.formatLayout")(0xc000114610),},
YAxis: github.com/360EntSecGroup-Skylar/excelize.formatChartAxis {
Crossing: "",
MajorTickMark: "",
MinorTickMark: "",
MinorUnitType: "",
MajorUnit: 0,
MajorUnitType: "",
DisplayUnits: "",
DisplayUnitsVisible: false,
DateAxis: false,
ReverseOrder: false,
Maximum: 0,
Minimum: 0,
NumFormat: "",
NumFont: (struct { Color string "json:"color""; Bold bool "json:"bold""; Italic bool "json:"italic""; Underline bool "json:"underline"" })(0xc0001146c0),
NameLayout: (
"github.com/360EntSecGroup-Skylar/excelize.formatLayout")(0xc0001146d8),},
Chartarea: struct { Border struct { None bool "json:"none"" } "json:"border""; Fill struct { Color string "json:"color"" } "json:"fill""; Pattern struct { Pattern string "json:"pattern""; FgColor string "json:"fg_color""; BgColor string "json:"bg_color"" } "json:"pattern"" } {
Border: (*struct { None bool "json:"none"" })(0xc0001146f8),
Fill: (*struct { Color string "json:"color"" })(0xc000114700),
Pattern: (*struct { Pattern string "json:"pattern""; FgColor string "json:"fg_color""; BgColor string "json:"bg_color"" })(0xc000114710),},
Plotarea: struct { ShowBubbleSize bool "json:"show_bubble_size""; ShowCatName bool "json:"show_cat_name""; ShowLeaderLines bool "json:"show_leader_lines""; ShowPercent bool "json:"show_percent""; ShowSerName bool "json:"show_series_name""; ShowVal bool "json:"show_val""; Gradient struct { Colors []string "json:"colors"" } "json:"gradient""; Border struct { Color string "json:"color""; Width int "json:"width""; DashType string "json:"dash_type"" } "json:"border""; Fill struct { Color string "json:"color"" } "json:"fill""; Layout github.com/360EntSecGroup-Skylar/excelize.formatLayout "json:"layout"" } {
ShowBubbleSize: true,
ShowCatName: false,
ShowLeaderLines: false,
ShowPercent: true,
ShowSerName: true,
ShowVal: true,
Gradient: (*struct { Colors []string "json:"colors"" })(0xc000114748),
Border: (*struct { Color string "json:"color""; Width int "json:"width""; DashType string "json:"dash_type"" })(0xc000114760),
Fill: (struct { Color string "json:"color"" })(0xc000114788),
Layout: (
"github.com/360EntSecGroup-Skylar/excelize.formatLayout")(0xc000114798),},
ShowBlanksAs: "zero",
ShowHiddenData: false,
SetRotation: 0,
SetHoleSize: 0,}
(dlv)

・・・・・・・・・・・・・・・・・・・・・・・・・・・・

test02.go
When there are seven types of comparison targets...

(dlv)

github.com/360EntSecGroup-Skylar/excelize.(File).AddChart() C:/Go/src/github.com/360EntSecGroup-Skylar/excelize/chart.go:470 (PC: 0x5544a5)
465: drawingRID := f.addDrawingRelationships(drawingID, SourceRelationshipChart, "../charts/chart"+strconv.Itoa(chartID)+".xml", "")
466: err = f.addDrawingChart(sheet, drawingXML, cell, formatSet.Dimension.Width, formatSet.Dimension.Height, drawingRID, &formatSet.Format)
467: if err != nil {
468: return err
469: }
=> 470: f.addChart(formatSet)
471: f.addContentTypePart(chartID, "chart")
472: f.addContentTypePart(drawingID, "drawings")
473: return err
474: }
475:
(dlv) p formatSet
github.com/360EntSecGroup-Skylar/excelize.formatChart {
Type: "line",
Series: []github.com/360EntSecGroup-Skylar/excelize.formatChartSeries len: 7, cap: 9, [
(
"github.com/360EntSecGroup-Skylar/excelize.formatChartSeries")(0xc0000fd180),
(
"github.com/360EntSecGroup-Skylar/excelize.formatChartSeries")(0xc0000fd218),
("github.com/360EntSecGroup-Skylar/excelize.formatChartSeries")(0xc0000fd2b0),
(
"github.com/360EntSecGroup-Skylar/excelize.formatChartSeries")(0xc0000fd348),
("github.com/360EntSecGroup-Skylar/excelize.formatChartSeries")(0xc0000fd3e0),
(
"github.com/360EntSecGroup-Skylar/excelize.formatChartSeries")(0xc0000fd478),
("github.com/360EntSecGroup-Skylar/excelize.formatChartSeries")(0xc0000fd510),
],
Format: github.com/360EntSecGroup-Skylar/excelize.formatPicture {FPrintsWithSheet: true, FLocksWithSheet: false, NoChangeAspect: false, OffsetX: 15, OffsetY: 10, XScale: 1, YScale: 1, Hyperlink: "", HyperlinkType: "", Positioning: ""},
Dimension: github.com/360EntSecGroup-Skylar/excelize.formatChartDimension {Width: 480, Height: 290},
Legend: github.com/360EntSecGroup-Skylar/excelize.formatChartLegend {
None: false,
DeleteSeries: []int len: 0, cap: 0, nil,
Font: (
"github.com/360EntSecGroup-Skylar/excelize.formatFont")(0xc0001124b0),
Layout: ("github.com/360EntSecGroup-Skylar/excelize.formatLayout")(0xc0001124f0),
Position: "top",
ShowLegendEntry: false,
ShowLegendKey: false,},
Title: github.com/360EntSecGroup-Skylar/excelize.formatChartTitle {
None: false,
Name: "Fruit Line Chart",
Overlay: false,
Layout: (
"github.com/360EntSecGroup-Skylar/excelize.formatLayout")(0xc000112548),},
XAxis: github.com/360EntSecGroup-Skylar/excelize.formatChartAxis {
Crossing: "",
MajorTickMark: "",
MinorTickMark: "",
MinorUnitType: "",
MajorUnit: 0,
MajorUnitType: "",
DisplayUnits: "",
DisplayUnitsVisible: false,
DateAxis: false,
ReverseOrder: false,
Maximum: 0,
Minimum: 0,
NumFormat: "",
NumFont: (struct { Color string "json:"color""; Bold bool "json:"bold""; Italic bool "json:"italic""; Underline bool "json:"underline"" })(0xc0001125f8),
NameLayout: (
"github.com/360EntSecGroup-Skylar/excelize.formatLayout")(0xc000112610),},
YAxis: github.com/360EntSecGroup-Skylar/excelize.formatChartAxis {
Crossing: "",
MajorTickMark: "",
MinorTickMark: "",
MinorUnitType: "",
MajorUnit: 0,
MajorUnitType: "",
DisplayUnits: "",
DisplayUnitsVisible: false,
DateAxis: false,
ReverseOrder: false,
Maximum: 0,
Minimum: 0,
NumFormat: "",
NumFont: (struct { Color string "json:"color""; Bold bool "json:"bold""; Italic bool "json:"italic""; Underline bool "json:"underline"" })(0xc0001126c0),
NameLayout: (
"github.com/360EntSecGroup-Skylar/excelize.formatLayout")(0xc0001126d8),},
Chartarea: struct { Border struct { None bool "json:"none"" } "json:"border""; Fill struct { Color string "json:"color"" } "json:"fill""; Pattern struct { Pattern string "json:"pattern""; FgColor string "json:"fg_color""; BgColor string "json:"bg_color"" } "json:"pattern"" } {
Border: (*struct { None bool "json:"none"" })(0xc0001126f8),
Fill: (*struct { Color string "json:"color"" })(0xc000112700),
Pattern: (*struct { Pattern string "json:"pattern""; FgColor string "json:"fg_color""; BgColor string "json:"bg_color"" })(0xc000112710),},
Plotarea: struct { ShowBubbleSize bool "json:"show_bubble_size""; ShowCatName bool "json:"show_cat_name""; ShowLeaderLines bool "json:"show_leader_lines""; ShowPercent bool "json:"show_percent""; ShowSerName bool "json:"show_series_name""; ShowVal bool "json:"show_val""; Gradient struct { Colors []string "json:"colors"" } "json:"gradient""; Border struct { Color string "json:"color""; Width int "json:"width""; DashType string "json:"dash_type"" } "json:"border""; Fill struct { Color string "json:"color"" } "json:"fill""; Layout github.com/360EntSecGroup-Skylar/excelize.formatLayout "json:"layout"" } {
ShowBubbleSize: true,
ShowCatName: false,
ShowLeaderLines: false,
ShowPercent: true,
ShowSerName: true,
ShowVal: true,
Gradient: (*struct { Colors []string "json:"colors"" })(0xc000112748),
Border: (*struct { Color string "json:"color""; Width int "json:"width""; DashType string "json:"dash_type"" })(0xc000112760),
Fill: (struct { Color string "json:"color"" })(0xc000112788),
Layout: (
"github.com/360EntSecGroup-Skylar/excelize.formatLayout")(0xc000112798),},
ShowBlanksAs: "zero",
ShowHiddenData: false,
SetRotation: 0,
SetHoleSize: 0,}
(dlv)

delve_test01.txt
delve_test02.txt

@GinSanaduki GinSanaduki changed the title When creating a graph with the AddChart function, drawing1.xml gets corrupted if the comparison target is 7 or more. When creating a graph with the AddChart function, drawing1.xml(chart1.xml) gets corrupted if the comparison target is 7 or more. Jun 8, 2019
@xuri xuri added confirmed This issue can be reproduced in progress Working in progress labels Jun 8, 2019
@xuri xuri closed this as completed in 46a3632 Jun 9, 2019
@xuri xuri removed the in progress Working in progress label Jun 9, 2019
@xuri
Copy link
Member

xuri commented Jun 9, 2019

Hi @GinSanaduki, thanks for your issue. I have fixed it. Please try to upgrade the library with the master branch code.

@GinSanaduki
Copy link
Author

Hi @xuri, thanks for reply.
I'm done checking the fix. It's working properly.
Thanks for your prompt response.

fix

nullfy pushed a commit to nullfy/excelize that referenced this issue Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed This issue can be reproduced
Projects
None yet
Development

No branches or pull requests

2 participants