@@ -312,11 +312,11 @@ func TestAddChart(t *testing.T) {
312
312
// Test with illegal cell reference
313
313
assert .EqualError (t , f .AddChart ("Sheet2" , "A" , & Chart {Type : Col , Series : series , Format : format , Legend : legend , Title : []RichTextRun {{Text : "2D Column Chart" }}, PlotArea : plotArea , ShowBlanksAs : "zero" }), newCellNameToCoordinatesError ("A" , newInvalidCellNameError ("A" )).Error ())
314
314
// Test with unsupported chart type
315
- assert .EqualError (t , f .AddChart ("Sheet2" , "BD32" , & Chart {Type : 0x37 , Series : series , Format : format , Legend : legend , Title : []RichTextRun {{Text : "Bubble 3D Chart" }}, PlotArea : plotArea , ShowBlanksAs : "zero" }), newUnsupportedChartType (0x37 ).Error ())
315
+ assert .EqualError (t , f .AddChart ("Sheet2" , "BD32" , & Chart {Type : 0x39 , Series : series , Format : format , Legend : legend , Title : []RichTextRun {{Text : "Bubble 3D Chart" }}, PlotArea : plotArea , ShowBlanksAs : "zero" }), newUnsupportedChartType (0x39 ).Error ())
316
316
// Test add combo chart with invalid format set
317
317
assert .EqualError (t , f .AddChart ("Sheet2" , "BD32" , & Chart {Type : Col , Series : series , Format : format , Legend : legend , Title : []RichTextRun {{Text : "2D Column Chart" }}, PlotArea : plotArea , ShowBlanksAs : "zero" }, nil ), ErrParameterInvalid .Error ())
318
318
// Test add combo chart with unsupported chart type
319
- assert .EqualError (t , f .AddChart ("Sheet2" , "BD64" , & Chart {Type : BarOfPie , Series : []ChartSeries {{Name : "Sheet1!$A$30" , Categories : "Sheet1!$A$30:$D$37" , Values : "Sheet1!$B$30:$B$37" }}, Format : format , Legend : legend , Title : []RichTextRun {{Text : "Bar of Pie Chart" }}, PlotArea : plotArea , ShowBlanksAs : "zero" , XAxis : ChartAxis {MajorGridLines : true }, YAxis : ChartAxis {MajorGridLines : true }}, & Chart {Type : 0x37 , Series : []ChartSeries {{Name : "Sheet1!$A$30" , Categories : "Sheet1!$A$30:$D$37" , Values : "Sheet1!$B$30:$B$37" }}, Format : format , Legend : legend , Title : []RichTextRun {{Text : "Bar of Pie Chart" }}, PlotArea : plotArea , ShowBlanksAs : "zero" , XAxis : ChartAxis {MajorGridLines : true }, YAxis : ChartAxis {MajorGridLines : true }}), newUnsupportedChartType (0x37 ).Error ())
319
+ assert .EqualError (t , f .AddChart ("Sheet2" , "BD64" , & Chart {Type : BarOfPie , Series : []ChartSeries {{Name : "Sheet1!$A$30" , Categories : "Sheet1!$A$30:$D$37" , Values : "Sheet1!$B$30:$B$37" }}, Format : format , Legend : legend , Title : []RichTextRun {{Text : "Bar of Pie Chart" }}, PlotArea : plotArea , ShowBlanksAs : "zero" , XAxis : ChartAxis {MajorGridLines : true }, YAxis : ChartAxis {MajorGridLines : true }}, & Chart {Type : 0x39 , Series : []ChartSeries {{Name : "Sheet1!$A$30" , Categories : "Sheet1!$A$30:$D$37" , Values : "Sheet1!$B$30:$B$37" }}, Format : format , Legend : legend , Title : []RichTextRun {{Text : "Bar of Pie Chart" }}, PlotArea : plotArea , ShowBlanksAs : "zero" , XAxis : ChartAxis {MajorGridLines : true }, YAxis : ChartAxis {MajorGridLines : true }}), newUnsupportedChartType (0x39 ).Error ())
320
320
// Test add chart with series transparency value exceeds limit
321
321
assert .Equal (t , ErrTransparency , f .AddChart ("Sheet1" , "BD64" , & Chart {Type : Col , Series : []ChartSeries {{Name : "Sheet1!$A$30" , Categories : "Sheet1!$B$29:$D$29" , Values : "Sheet1!$B$30:$D$30" , Fill : Fill {Transparency : 110 }}}}))
322
322
// Test add chart with transparency value exceeds limit
@@ -327,6 +327,113 @@ func TestAddChart(t *testing.T) {
327
327
f .ContentTypes = nil
328
328
f .Pkg .Store (defaultXMLPathContentTypes , MacintoshCyrillicCharset )
329
329
assert .EqualError (t , f .AddChart ("Sheet1" , "P1" , & Chart {Type : Col , Series : []ChartSeries {{Name : "Sheet1!$A$30" , Categories : "Sheet1!$B$29:$D$29" , Values : "Sheet1!$B$30:$D$30" }}, Title : []RichTextRun {{Text : "2D Column Chart" }}}), "XML syntax error on line 1: invalid UTF-8" )
330
+
331
+ t .Run ("for_create_stock_chart" , func (t * testing.T ) {
332
+ f := NewFile ()
333
+ for i , row := range [][]interface {}{
334
+ {"Date" , "Volume" , "Open" , "High" , "Low" , "Close" },
335
+ {45593 , 14864000 , 431.66 , 431.94 , 426.3 , 426.59 },
336
+ {45590 , 16899100 , 426.76 , 432.52 , 426.57 , 428.15 },
337
+ {45589 , 13581600 , 425.33 , 425.98 , 422.4 , 424.73 },
338
+ {45588 , 19654400 , 430.86 , 431.08 , 422.53 , 424.6 },
339
+ {45587 , 25482200 , 418.49 , 430.58 , 418.04 , 427.51 },
340
+ {45586 , 14206100 , 416.12 , 418.96 , 413.75 , 418.78 },
341
+ {45583 , 17145300 , 417.14 , 419.65 , 416.26 , 418.16 },
342
+ {45582 , 14820000 , 422.36 , 422.5 , 415.59 , 416.72 },
343
+ {45581 , 15508900 , 415.17 , 416.36 , 410.48 , 416.12 },
344
+ {45580 , 18900200 , 422.18 , 422.48 , 415.26 , 418.74 },
345
+ {45579 , 16653100 , 417.77 , 424.04 , 417.52 , 419.14 },
346
+ {45576 , 14144900 , 416.14 , 417.13 , 413.25 , 416.32 },
347
+ {45575 , 13848400 , 415.23 , 417.35 , 413.15 , 415.84 },
348
+ {45574 , 14974300 , 415.86 , 420.38 , 414.3 , 417.46 },
349
+ {45573 , 19229300 , 410.9 , 415.66 , 408.17 , 414.71 },
350
+ {45572 , 20919800 , 416 , 417.11 , 409 , 409.54 },
351
+ {45569 , 19169700 , 418.24 , 419.75 , 414.97 , 416.06 },
352
+ {45568 , 13686400 , 417.63 , 419.55 , 414.29 , 416.54 },
353
+ {45567 , 16582300 , 422.58 , 422.82 , 416.71 , 417.13 },
354
+ {45566 , 19092900 , 428.45 , 428.48 , 418.81 , 420.69 },
355
+ {45565 , 16807300 , 428.21 , 430.42 , 425.37 , 430.3 },
356
+ } {
357
+ cell , err := CoordinatesToCellName (1 , i + 1 )
358
+ assert .NoError (t , err )
359
+ assert .NoError (t , f .SetSheetRow ("Sheet1" , cell , & row ))
360
+ }
361
+ style , err := f .NewStyle (& Style {NumFmt : 15 })
362
+ assert .NoError (t , err )
363
+ assert .NoError (t , f .SetColStyle ("Sheet1" , "A" , style ))
364
+
365
+ assert .NoError (t , f .AddChart ("Sheet1" , "G1" , & Chart {
366
+ Type : StockHighLowClose ,
367
+ Series : []ChartSeries {
368
+ {Name : "Sheet1!$D$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$D$2:$D$22" },
369
+ {Name : "Sheet1!$E$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$E$2:$E$22" },
370
+ {Name : "Sheet1!$F$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$F$2:$F$22" },
371
+ },
372
+ Legend : ChartLegend {Position : "none" },
373
+ Title : []RichTextRun {{Text : "High-Low-Close Stock Chart" }},
374
+ XAxis : ChartAxis {NumFmt : ChartNumFmt {CustomNumFmt : "d-mmm-yy" }},
375
+ }))
376
+ assert .NoError (t , f .AddChart ("Sheet1" , "G16" , & Chart {
377
+ Type : StockOpenHighLowClose ,
378
+ Series : []ChartSeries {
379
+ {Name : "Sheet1!$C$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$C$2:$C$22" },
380
+ {Name : "Sheet1!$D$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$D$2:$D$22" },
381
+ {Name : "Sheet1!$E$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$E$2:$E$22" },
382
+ {Name : "Sheet1!$F$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$F$2:$F$22" },
383
+ },
384
+ Legend : ChartLegend {Position : "none" },
385
+ Title : []RichTextRun {{Text : "Open-High-Low-Close Stock Chart" }},
386
+ XAxis : ChartAxis {NumFmt : ChartNumFmt {CustomNumFmt : "d-mmm-yy" }},
387
+ PlotArea : ChartPlotArea {
388
+ UpBars : ChartUpDownBar {
389
+ Border : ChartLine {Type : ChartLineNone },
390
+ Fill : Fill {Type : "pattern" , Color : []string {"00B050" }, Pattern : 1 },
391
+ },
392
+ DownBars : ChartUpDownBar {
393
+ Border : ChartLine {Type : ChartLineNone },
394
+ Fill : Fill {Type : "pattern" , Color : []string {"FF0000" }, Pattern : 1 },
395
+ },
396
+ },
397
+ }))
398
+ assert .NoError (t , f .AddChart ("Sheet1" , "O1" , & Chart {
399
+ Type : Col ,
400
+ Series : []ChartSeries {
401
+ {Name : "Sheet1!$B$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$B$2:$B$22" },
402
+ },
403
+ VaryColors : boolPtr (false ),
404
+ XAxis : ChartAxis {NumFmt : ChartNumFmt {CustomNumFmt : "d-mmm-yy" }},
405
+ YAxis : ChartAxis {NumFmt : ChartNumFmt {CustomNumFmt : "#,##0" }},
406
+ Title : []RichTextRun {{Text : "Volume-High-Low-Close Stock Chart" }},
407
+ }, & Chart {
408
+ Type : StockHighLowClose ,
409
+ Series : []ChartSeries {
410
+ {Name : "Sheet1!$D$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$D$2:$D$22" },
411
+ {Name : "Sheet1!$E$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$E$2:$E$22" },
412
+ {Name : "Sheet1!$F$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$F$2:$F$22" },
413
+ },
414
+ YAxis : ChartAxis {Secondary : true },
415
+ }))
416
+ assert .NoError (t , f .AddChart ("Sheet1" , "O16" , & Chart {
417
+ Type : Col ,
418
+ Series : []ChartSeries {
419
+ {Name : "Sheet1!$B$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$B$2:$B$22" },
420
+ },
421
+ VaryColors : boolPtr (false ),
422
+ XAxis : ChartAxis {NumFmt : ChartNumFmt {CustomNumFmt : "d-mmm-yy" }},
423
+ YAxis : ChartAxis {NumFmt : ChartNumFmt {CustomNumFmt : "#,##0" }},
424
+ Title : []RichTextRun {{Text : "Volume-Open-High-Low-Close Stock Chart" }},
425
+ }, & Chart {
426
+ Type : StockOpenHighLowClose ,
427
+ Series : []ChartSeries {
428
+ {Name : "Sheet1!$C$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$C$2:$C$22" },
429
+ {Name : "Sheet1!$D$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$D$2:$D$22" },
430
+ {Name : "Sheet1!$E$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$E$2:$E$22" },
431
+ {Name : "Sheet1!$F$1" , Categories : "Sheet1!$A$2:$A$22" , Values : "Sheet1!$F$2:$F$22" },
432
+ },
433
+ YAxis : ChartAxis {Secondary : true },
434
+ }))
435
+ assert .NoError (t , f .SaveAs (filepath .Join ("test" , "TestAddChartStock.xlsx" )))
436
+ })
330
437
}
331
438
332
439
func TestAddChartSheet (t * testing.T ) {
@@ -363,7 +470,7 @@ func TestAddChartSheet(t *testing.T) {
363
470
// Test add chartsheet with invalid sheet name
364
471
assert .EqualError (t , f .AddChartSheet ("Sheet:1" , nil , & Chart {Type : Col3DClustered , Series : series , Title : []RichTextRun {{Text : "Fruit 3D Clustered Column Chart" }}}), ErrSheetNameInvalid .Error ())
365
472
// Test with unsupported chart type
366
- assert .EqualError (t , f .AddChartSheet ("Chart2" , & Chart {Type : 0x37 , Series : series , Title : []RichTextRun {{Text : "Fruit 3D Clustered Column Chart" }}}), newUnsupportedChartType (0x37 ).Error ())
473
+ assert .EqualError (t , f .AddChartSheet ("Chart2" , & Chart {Type : 0x39 , Series : series , Title : []RichTextRun {{Text : "Fruit 3D Clustered Column Chart" }}}), newUnsupportedChartType (0x39 ).Error ())
367
474
368
475
assert .NoError (t , f .UpdateLinkedValue ())
369
476
0 commit comments