I use Haskell-Chart according to the example eample-1. Haskell-Chart generates content to file
toFile def "example1_big.png" $ do
...
Is it possible generate content of chart to ByteString instead file? I can not find a solution in the documentation.
Unfortunately this is not possible is a direct manner. toFile
calls upon functions in the cairo
library like withPDFSurface
, withSVGSurface
which themselves call into the cairo C-library and only take file names.
You can always write to a temporary file and read the contents back in like this:
import System.IO.Temp -- from the temporary package
import qualified Data.ByteString.Char8 as BS
...
bs <- withSystemTempFile "chart-XXXXXXX" $ \path _ -> do
toFile def path $ do ...
BS.readFile path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With