0

谁能告诉我如何在 PDF 文件中使用 rails 3.2 中的 prawn 绘制双条形图。我能够在 PDF 上获得单条形图,但我不知道如何在 PDF 文件中绘制双条形图。有什么方法可以使用 prawn 创建多个条形图,或者是否有任何其他 gem 可以做到这一点,但我不想在我的项目中间使用其他 gem 所以如果有人可以帮助我,那将不胜感激。谢谢

4

1 回答 1

0

我认为为时已晚,但它仍然可以对其他人有所帮助。使用虾图

示例

require 'prawn-graph'

series = []
series << Prawn::Graph::Series.new([4,9,3,2,1,6,2,8,2,3,4,9,2],  title: "A label for a series", type: :bar)

series << Prawn::Graph::Series.new([5,4,3,2,7,9,2,8,7,5,4,9,2],  title: "Another label", type: :line, mark_average: true, mark_minimum: true)

series << Prawn::Graph::Series.new([1,2,3,4,5,9,6,4,5,6,3,2,11], title: "Yet another label", type: :bar)

series << Prawn::Graph::Series.new([1,2,3,4,5,12,6,4,5,6,3,2,9].shuffle, title: "One final label", type: :line, mark_average: true, mark_maximum: true)

xaxis_labels = ['0900', '1000', '1100', '1200', '1300', '1400', '1500', '1600', '1700', '1800', '1900', '2000', '2100']

Prawn::Document.generate('test.pdf') do

    graph series, width: 500, height: 200, title: "A Title for the chart", at: [10,700], xaxis_labels: xaxis_labels

end
于 2019-09-11T12:57:19.590 回答