
Security News
CISA’s 2025 SBOM Guidance Adds Hashes, Licenses, Tool Metadata, and Context
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Create SVG mini charts with Ruby
$ gem install minichart
Or with bundler:
gem 'minichart'
Require and optionally include the library:
require 'minichart'
include Minichart
Initialize a chart with data, and optional options:
data = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9]
chart = AreaChart.new data, color: 'blue'
Get the full SVG output by calling #render
:
puts chart.render
#=> <?xml version="1.0" standalone="no"?>
# <svg> ... </svg>
Save it to file, by calling #save
:
chart.save "my-chart.svg"
Get its inner SVG string by calling #to_s
:
puts chart.to_s
#=> <polyline fill="blue" stroke="blue" stroke-width="2" points="..."/>
The objects returned from all the mini chart classes are Victor::SVG objects, so they support all methods supported by it as well.
LineChart.new [10, 30, 20, 40, 30], background: '#eee',
height: 50, width: 250, color: 'green'
BarChart.new [10, 30, 20, 40, 30], background: '#eee',
height: 50, width: 250, color: 'green'
AreaChart.new [10, 30, 20, 40, 30], background: '#eee',
height: 50, width: 250, color: 'green'
positive = HorizontalBarMeter.new 70,
height: 20, width: 250, background: '#9f9', color: 'green'
negative = HorizontalBarMeter.new -80,
height: 20, width: 250, background: '#f99', color: 'red'
dual = HorizontalBarMeter.new 80,
height: 20, width: 250, background: '#99f', color: 'blue',
mode: :dual, notches: [0]
Meter charts support additional options.
positive = VerticalBarMeter.new 70,
width: 20, height: 250, background: '#9f9', color: 'green'
negative = VerticalBarMeter.new -80,
width: 20, height: 250, background: '#f99', color: 'red'
dual = VerticalBarMeter.new 80,
width: 20, height: 250, background: '#99f', color: 'blue',
mode: :dual, notches: [0]
Meter charts support additional options.
HorizontalStatusLeds.new [1,1,-1,0,1,1,1,1,1,-1,-1,1],
background: '#ccc'
Led charts support additional options.
VerticalStatusLeds.new [1,1,1,1,-1,1,-1,1,0,1],
background: '#ccc'
Led charts support additional options.
Chart options can be set in one of three ways.
See or set default options for any chart class by calling its ::options
method:
# See all options
p AreaChart.options
#=> {:background=>"white", :height=>100, :width=>300, :stroke=>2, :style=>{}, :color=>"#66f"}
# Set a single default option
AreaChart.options[:color] = '#333'
# Set multiple options at once
AreaChart.options background: 'black', color: 'green'
Set options by providing a hash as the second argument on initialization:
chart = AreaChart.new data, height: 120, width: 500
After initialization, you can still update individual options:
chart = AreaChart.new data
chart.options[:background] = 'yellow'
Meter charts support these options in additon to the basic options:
:positive
, :negative
, :dual
or :auto
(default).
The :auto
mode will switch between :positive
and :negative
based on the
value.Led charts support these options in additon to the basic options (excluding
the color
option):
See more examples (code and SVG output) in the examples folder.
If you experience any issue, have a question or a suggestion, or if you wish to contribute, feel free to open an issue.
FAQs
Unknown package
We found that minichart demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.