Three years ago I played a bit with bar charts.
I started a YouTube channel and I like to create some bar charts.
An example is:
#!/usr/bin/env tclsh
package require Tk
package require BLT
package require sqlite3
set viewsArr {}
set weekArr {}
sqlite3 db ~/Databases/youtube.sqlite
db eval {
SELECT strftime('%W', dayDate, '+1 day') AS WeekNo
, SUM(dayViews) AS WeekTotals
FROM dayViews
WHERE WeekNo > '37'
GROUP BY WeekNo
ORDER BY WeekNo
} {
lappend viewsArr ${WeekTotals}
lappend weekArr ${WeekNo}
}
db close
blt::barchart .bc -plotbackground black
.bc axis configure y -stepsize 100
.bc element create best -xdata ${weekArr} -ydata ${viewsArr} -label {}
pack .bc -side top -expand yes -fill both
This gives a window with the bar chart. I can make a screen dump
of-course, but is there a way to also write the bar chart to a PNG
file?
What is a good resource for learning to work with Tk, (bar) charts and
the like?
Three years ago I played a bit with bar charts.
I started a YouTube channel and I like to create some bar charts.
An example is:
#!/usr/bin/env tclsh
package require Tk
package require BLT
package require sqlite3
set viewsArr {}
set weekArr {}
sqlite3 db ~/Databases/youtube.sqlite
db eval {
SELECT strftime('%W', dayDate, '+1 day') AS WeekNo
, SUM(dayViews) AS WeekTotals
FROM dayViews
WHERE WeekNo > '37'
GROUP BY WeekNo
ORDER BY WeekNo
} {
lappend viewsArr ${WeekTotals}
lappend weekArr ${WeekNo}
}
db close
blt::barchart .bc -plotbackground black
.bc axis configure y -stepsize 100
.bc element create best -xdata ${weekArr} -ydata ${viewsArr} -label {}
pack .bc -side top -expand yes -fill both
This gives a window with the bar chart. I can make a screen dump
of-course, but is there a way to also write the bar chart to a PNG
file?
What is a good resource for learning to work with Tk, (bar) charts and
the like?
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
Try something like:
package require img::window
image create photo bc -data .bc
bc write bar.png
greg writes:
Cecil Westerhof schrieb am Samstag, 21. Oktober 2023 um 14:44:10 UTC+2:
Three years ago I played a bit with bar charts.
I started a YouTube channel and I like to create some bar charts.
An example is:
#!/usr/bin/env tclsh
package require Tk
package require BLT
package require sqlite3
set viewsArr {}
set weekArr {}
sqlite3 db ~/Databases/youtube.sqlite
db eval {
SELECT strftime('%W', dayDate, '+1 day') AS WeekNo
, SUM(dayViews) AS WeekTotals
FROM dayViews
WHERE WeekNo > '37'
GROUP BY WeekNo
ORDER BY WeekNo
} {
lappend viewsArr ${WeekTotals}
lappend weekArr ${WeekNo}
}
db close
blt::barchart .bc -plotbackground black
.bc axis configure y -stepsize 100
.bc element create best -xdata ${weekArr} -ydata ${viewsArr} -label {}
pack .bc -side top -expand yes -fill both
This gives a window with the bar chart. I can make a screen dump
of-course, but is there a way to also write the bar chart to a PNG
file?
What is a good resource for learning to work with Tk, (bar) charts and
the like?
slides.pdf
https://blt.sourceforge.net/
https://wiki.tcl-lang.org/page/BLT+%2D+graph+%2D+printing+postscript
andAt the moment I use:
https://wiki.tcl-lang.org/page/BLT
.bc postscript configure -landscape yes -maxpect yes
.bc postscript output ytWeek.ps
And I convert it to png with:
gs -dSAFER -o ytWeek.png ytWeek.ps
Works reasonable, but there is a problem: left and right there is a transparency area of 135 pixels and above and under of 95 pixels.
How do I get rid of this area?
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
Cecil Westerhof schrieb am Samstag, 21. Oktober 2023 um 14:44:10 UTC+2:
Three years ago I played a bit with bar charts.
I started a YouTube channel and I like to create some bar charts.
An example is:
#!/usr/bin/env tclsh
package require Tk
package require BLT
package require sqlite3
set viewsArr {}
set weekArr {}
sqlite3 db ~/Databases/youtube.sqlite
db eval {
SELECT strftime('%W', dayDate, '+1 day') AS WeekNo
, SUM(dayViews) AS WeekTotals
FROM dayViews
WHERE WeekNo > '37'
GROUP BY WeekNo
ORDER BY WeekNo
} {
lappend viewsArr ${WeekTotals}
lappend weekArr ${WeekNo}
}
db close
blt::barchart .bc -plotbackground black
.bc axis configure y -stepsize 100
.bc element create best -xdata ${weekArr} -ydata ${viewsArr} -label {}
pack .bc -side top -expand yes -fill both
This gives a window with the bar chart. I can make a screen dump
of-course, but is there a way to also write the bar chart to a PNG
file?
What is a good resource for learning to work with Tk, (bar) charts and
the like?
slides.pdf
https://blt.sourceforge.net/
https://wiki.tcl-lang.org/page/BLT+%2D+graph+%2D+printing+postscript
and
https://wiki.tcl-lang.org/page/BLT
greg <[email protected]> writes:
Cecil Westerhof schrieb am Samstag, 21. Oktober 2023 um 14:44:10 UTC+2:
Three years ago I played a bit with bar charts.
I started a YouTube channel and I like to create some bar charts.
An example is:
#!/usr/bin/env tclsh
package require Tk
package require BLT
package require sqlite3
set viewsArr {}
set weekArr {}
sqlite3 db ~/Databases/youtube.sqlite
db eval {
SELECT strftime('%W', dayDate, '+1 day') AS WeekNo
, SUM(dayViews) AS WeekTotals
FROM dayViews
WHERE WeekNo > '37'
GROUP BY WeekNo
ORDER BY WeekNo
} {
lappend viewsArr ${WeekTotals}
lappend weekArr ${WeekNo}
}
db close
blt::barchart .bc -plotbackground black
.bc axis configure y -stepsize 100
.bc element create best -xdata ${weekArr} -ydata ${viewsArr} -label {}
pack .bc -side top -expand yes -fill both
This gives a window with the bar chart. I can make a screen dump
of-course, but is there a way to also write the bar chart to a PNG
file?
What is a good resource for learning to work with Tk, (bar) charts and
the like?
slides.pdf
https://blt.sourceforge.net/
https://wiki.tcl-lang.org/page/BLT+%2D+graph+%2D+printing+postscript
and
https://wiki.tcl-lang.org/page/BLT
At the moment I use:
.bc postscript configure -landscape yes -maxpect yes
.bc postscript output ytWeek.ps
And I convert it to png with:
gs -dSAFER -o ytWeek.png ytWeek.ps
Works reasonable, but there is a problem: left and right there is a transparency area of 135 pixels and above and under of 95 pixels.
How do I get rid of this area?
greg <[email protected]> writes:
Cecil Westerhof schrieb am Samstag, 21. Oktober 2023 um 14:44:10 UTC+2:
Three years ago I played a bit with bar charts.
I started a YouTube channel and I like to create some bar charts.
An example is:
#!/usr/bin/env tclsh
package require Tk
package require BLT
package require sqlite3
set viewsArr {}
set weekArr {}
sqlite3 db ~/Databases/youtube.sqlite
db eval {
SELECT strftime('%W', dayDate, '+1 day') AS WeekNo
, SUM(dayViews) AS WeekTotals
FROM dayViews
WHERE WeekNo > '37'
GROUP BY WeekNo
ORDER BY WeekNo
} {
lappend viewsArr ${WeekTotals}
lappend weekArr ${WeekNo}
}
db close
blt::barchart .bc -plotbackground black
.bc axis configure y -stepsize 100
.bc element create best -xdata ${weekArr} -ydata ${viewsArr} -label {}
pack .bc -side top -expand yes -fill both
This gives a window with the bar chart. I can make a screen dump
of-course, but is there a way to also write the bar chart to a PNG
file?
What is a good resource for learning to work with Tk, (bar) charts and
the like?
slides.pdf
https://blt.sourceforge.net/
https://wiki.tcl-lang.org/page/BLT+%2D+graph+%2D+printing+postscript
and
https://wiki.tcl-lang.org/page/BLT
At the moment I use:
.bc postscript configure -landscape yes -maxpect yes
.bc postscript output ytWeek.ps
And I convert it to png with:
gs -dSAFER -o ytWeek.png ytWeek.ps
Works reasonable, but there is a problem: left and right there is a transparency area of 135 pixels and above and under of 95 pixels.
How do I get rid of this area?
Three years ago I played a bit with bar charts.
I started a YouTube channel and I like to create some bar charts.
An example is:
#!/usr/bin/env tclsh
package require Tk
package require BLT
package require sqlite3
set viewsArr {}
set weekArr {}
sqlite3 db ~/Databases/youtube.sqlite
db eval {
SELECT strftime('%W', dayDate, '+1 day') AS WeekNo
, SUM(dayViews) AS WeekTotals
FROM dayViews
WHERE WeekNo > '37'
GROUP BY WeekNo
ORDER BY WeekNo
} {
lappend viewsArr ${WeekTotals}
lappend weekArr ${WeekNo}
}
db close
blt::barchart .bc -plotbackground black
.bc axis configure y -stepsize 100
.bc element create best -xdata ${weekArr} -ydata ${viewsArr}
-label {} pack .bc -side top -expand yes -fill both
This gives a window with the bar chart. I can make a screen dump
of-course, but is there a way to also write the bar chart to a PNG
file?
What is a good resource for learning to work with Tk, (bar) charts and
the like?
can't find package img::window
On Sat, 21 Oct 2023 14:30:10 +0200
Cecil Westerhof <[email protected]> wrote:
Three years ago I played a bit with bar charts.
I started a YouTube channel and I like to create some bar charts.
An example is:
#!/usr/bin/env tclsh
package require Tk
package require BLT
package require sqlite3
set viewsArr {}
set weekArr {}
sqlite3 db ~/Databases/youtube.sqlite
db eval {
SELECT strftime('%W', dayDate, '+1 day') AS WeekNo
, SUM(dayViews) AS WeekTotals
FROM dayViews
WHERE WeekNo > '37'
GROUP BY WeekNo
ORDER BY WeekNo
} {
lappend viewsArr ${WeekTotals}
lappend weekArr ${WeekNo}
}
db close
blt::barchart .bc -plotbackground black
.bc axis configure y -stepsize 100
.bc element create best -xdata ${weekArr} -ydata ${viewsArr}
-label {} pack .bc -side top -expand yes -fill both
This gives a window with the bar chart. I can make a screen dump
of-course, but is there a way to also write the bar chart to a PNG
file?
Yes. I tested this on Ubuntu 18 with package tk8.6-blt2.5, which gives
BLT version 2.5.3.
# Create a image to hold the graph, use the "snap" subcommand and then
# write the image to a file.
image create photo snapshot
.bc snap snapshot
snapshot write snapshot.png -format png
At Sat, 21 Oct 2023 21:38:28 +0200 Cecil Westerhof <[email protected]> wrote:
[email protected] writes:
Try something like:
package require img::window
image create photo bc -data .bc
bc write bar.png
Would be the best option, but I get:
can't find package img::window
If you are on a Linux system, you need to do:
sudo apt install TkImg
to install the package.
Yes. I tested this on Ubuntu 18 with package tk8.6-blt2.5, which gives
BLT version 2.5.3.
# Create a image to hold the graph, use the "snap" subcommand and then
# write the image to a file.
image create photo snapshot
.bc snap snapshot
snapshot write snapshot.png -format png
Works likes a charm.
Thanks.
Now I have to learn to get the most out of it. ;-)
can't find package img::window
you need the Img package. It can be found on sourceforge.net as tkimg
package require Img loads all the additional image format handlers.
package require img::window just loads the handler for reading Tk windows
Note the capitalized "I" when loading the overall package.
The png handler is already part of Tk
I use the ...Linux64 version of the package, however the documentation appears to only be in the source package.
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 157:46:02 |
| Calls: | 12,093 |
| Calls today: | 1 |
| Files: | 15,000 |
| Messages: | 6,517,755 |