Skip to content

Commit

Permalink
made some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kellemNegasi committed Oct 11, 2024
1 parent 867dce0 commit b932a86
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion report/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ The example explains how to create PDF reports using UniPDF, it also shows you h
- [pdf_report.go](pdf_report.go) The example showcases PDF report generation with UniPDF's creator package. The output is saved as unidoc-report.pdf which illustrates some of the features of the creator.
- [pdf_tables.go](pdf_tables.go) The example showcases PDF tables features using UniPDF's creator package. The output is saved as UniPDF-tables.pdf which illustrates some of the features of the creator.
- [pdf_custom_toc.go](pdf_custom_toc.go) The example showcases the capabilities of generating PDF custom table of contents layout. The output is saved as pdf-custom-toc.pdf.
- [pdf_report_from_csv.go](pdf_report_from_csv.go) This example showcases how to prepared report from csv data.
- [pdf_report_from_csv.go](pdf_report_from_csv.go) This example showcases how to prepare a report from csv data.
30 changes: 22 additions & 8 deletions report/pdf_report_from_csv.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* This example showcases how to prepare report with charts from csv data.
*
* Run as: go run pdf_report_from_csv.go
*/
package main

import (
Expand All @@ -13,6 +18,7 @@ import (
"github.com/unidoc/unichart/dataset"
"github.com/unidoc/unichart/dataset/sequence"
"github.com/unidoc/unichart/render"
"github.com/unidoc/unipdf/v3/common"
"github.com/unidoc/unipdf/v3/common/license"
"github.com/unidoc/unipdf/v3/creator"
"github.com/unidoc/unipdf/v3/model"
Expand Down Expand Up @@ -46,19 +52,22 @@ type salesData struct {
func main() {
robotoFontRegular, err := model.NewPdfFontFromTTFFile("./Roboto-Regular.ttf")
if err != nil {
panic(err)
common.Log.Info("Failed to load font %s", err)
return
}

robotoFontPro, err := model.NewPdfFontFromTTFFile("./Roboto-Bold.ttf")
if err != nil {
panic(err)
common.Log.Info("Failed to load font %s", err)
return
}

c := creator.New()
filePath := "./test-data.csv"
data, _, err := loadCsv(filePath)
if err != nil {
panic("failed to load data ")
common.Log.Info("failed to load data %s", err)
return
}

cumulativeSums := make(map[string]float64) // Cumulative Sales by person
Expand Down Expand Up @@ -129,7 +138,8 @@ func main() {
err = c.Draw(barChart)

if err != nil {
panic(err)
common.Log.Info("Failed to draw chart. %s.", err)
return
}

// Create pie chart
Expand All @@ -146,7 +156,8 @@ func main() {
pieChart.SetPos(360, 170)
err = c.Draw(pieChart)
if err != nil {
panic(err)
common.Log.Info("Failed to draw pie chart. %s", err)
return
}

// Create Line Chart
Expand All @@ -160,12 +171,14 @@ func main() {
err = c.Draw(lineChart)

if err != nil {
panic(err)
common.Log.Info("Failed to draw line chart. %s", err)
return
}

err = c.WriteToFile("report_from_csv.pdf")
if err != nil {
panic(err)
common.Log.Info("Failed to write to file. %s", err)
return
}
}

Expand Down Expand Up @@ -223,7 +236,8 @@ func doFirstPage(c *creator.Creator, fontRegular *model.PdfFont, fontBold *model
// createBarChart creates a bar chart given `valMap`.
func createBarChart(valMap map[string]float64) render.ChartRenderable {
chart := &unichart.BarChart{
Bars: parseChartValMap(valMap),
Bars: parseChartValMap(valMap),
BarWidth: 35,
}

// Set Y-axis custom range.
Expand Down
Binary file modified report/report_from_csv.pdf
Binary file not shown.
Binary file modified report/report_from_csv_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b932a86

Please sign in to comment.