Skip to content
Vitaly Bragilevsky edited this page Dec 1, 2024 · 2 revisions

It's possible to plot text on chart using Plot.Annotation:

annotation chart

import Graphics.Rendering.Chart
import Graphics.Rendering.Chart.Backend.Cairo
import Data.Default.Class
import Control.Lens

ws = [(1, 5, "hello"), (2, 3, "chart"), (3, 2, "diagram"), (3, 3, "text"), (4, 1, "annotation"), (2, 2, "plot")] :: [(Int, Int, String)]

chart = toRenderable layout
  where
    layout = layout_title .~ "texts"
           $ layout_plots .~ [toPlot texts]
           $ def

    texts = plot_annotation_values .~ ws
          $ plot_annotation_angle .~ 20 -- degrees
          $ plot_annotation_style .~ fontStyle
          $ plot_annotation_hanchor .~ HTA_Centre -- the horizontal anchor around which the text is rotated
          $ plot_annotation_vanchor .~ VTA_Centre -- the vertical anchor
          $ def

    fontStyle = font_size .~ 15
              $ font_weight .~ FontWeightBold
              $ def

main = renderableToFile def "chart.png" chart
Clone this wiki locally