1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
SVG::Graph
============
[](https://travis-ci.com/lumean/svg-graph2)
[](https://codeclimate.com/github/lumean/svg-graph2/maintainability)
[](https://codeclimate.com/github/lumean/svg-graph2/test_coverage)
[](https://percy.io/a5e00e98/svg-graph2)
Description
-----------
This repo is the continuation of the original [SVG::Graph library](http://www.germane-software.com/software/SVG/SVG::Graph/) by Sean Russell. I'd like to thank Claudio Bustos for giving me permissions to continue publishing the gem under it's original name: [svg-graph](https://rubygems.org/gems/svg-graph)
[Changelog](../master/History.txt)
I'm maintaing in my free time, so I can't promise on any deadlines. Please notify me (via github messages or on the Issues section) if you find any bug.
Contribute
-----
Pull requests are very welcome :-)
Usage
-----
For a complete list of configuration options please have a look at the source - most important [Graph.rb](../master/lib/SVG/Graph/Graph.rb), also checkout the subclasses (Pie, Bar, etc.) as they might provide additional options.
You can require everything at once
```ruby
require 'svggraph'
```
or only the individual parts you need
```ruby
require 'SVG/Graph/Bar'
require 'SVG/Graph/Line'
...
```
In the following some examples to get you up to speed.
### Bar
```ruby
require 'SVG/Graph/Bar'
x_axis = ['1-10', '10-30', '30-50', '50-70', 'older']
options = {
:width => 640,
:height => 300,
:stack => :side, # the stack option is valid for Bar graphs only
:fields => x_axis,
:graph_title => "kg per head and year chocolate consumption",
:show_graph_title => true,
:show_x_title => true,
:x_title => 'Age in years',
:show_y_title => true,
:y_title => 'kg/year',
:y_title_location => :end,
:no_css => true
}
male_data = [2, 4, 6, 4, 2]
female_data = [1, 5, 4, 5, 2.7]
g = SVG::Graph::Bar.new(options)
g.add_data( {
:data => female_data,
:title => "Female"
})
g.add_data( {
:data => male_data,
:title => "Male"
})
# graph.burn # this returns a full valid xml document containing the graph
# graph.burn_svg_only # this only returns the <svg>...</svg> node
File.open('bar.svg', 'w') {|f| f.write(g.burn_svg_only)}
```

### BarHorizontal

### ErrBar

### Line

### Pie

### Plot

### Schedule

### TimeSeries

### C3js
Source: [C3js.rb](../master/examples/c3js.rb)
[Link to Preview](https://cdn.rawgit.com/lumean/svg-graph2/master/examples/c3js.html)
Build
-----
* Test
`bundle exec rake`
* Build gem:
`gem build svg-graph.gemspec`
* Install:
`gem install svg-graph-\<version>.gem`
Percy.io integration
---
https://docs.percy.io/docs/travis-ci
https://docs.percy.io/docs/snapshot-cli-command
|