ChartDirector 6.0 (Ruby Edition)

Built-In Symbols




This example demonstrates the built-in symbols supported by ChartDirector.

Source Code Listing

[Ruby On Rails Version - Controller] app/controllers/builtinsymbols_controller.rb
require("chartdirector")

class BuiltinsymbolsController < ApplicationController

    def index()
        @title = "Built-in Symbols"
        @ctrl_file = File.expand_path(__FILE__)
        @noOfCharts = 1
        render :template => "templates/chartview"
    end

    #
    # Render and deliver the chart
    #
    def getchart()
        # Some ChartDirector built-in symbols
        symbols = [ChartDirector::CircleShape, ChartDirector::GlassSphereShape,
            ChartDirector::GlassSphere2Shape, ChartDirector::SolidSphereShape,
            ChartDirector::SquareShape, ChartDirector::DiamondShape, ChartDirector::TriangleShape,
            ChartDirector::RightTriangleShape, ChartDirector::LeftTriangleShape,
            ChartDirector::InvertedTriangleShape, ChartDirector::StarShape(3),
            ChartDirector::StarShape(4), ChartDirector::StarShape(5), ChartDirector::StarShape(6),
            ChartDirector::StarShape(7), ChartDirector::StarShape(8), ChartDirector::StarShape(9),
            ChartDirector::StarShape(10), ChartDirector::PolygonShape(5),
            ChartDirector::Polygon2Shape(5), ChartDirector::PolygonShape(6),
            ChartDirector::Polygon2Shape(6), ChartDirector::Polygon2Shape(7),
            ChartDirector::CrossShape(0.1), ChartDirector::CrossShape(0.2),
            ChartDirector::CrossShape(0.3), ChartDirector::CrossShape(0.4),
            ChartDirector::CrossShape(0.5), ChartDirector::CrossShape(0.6),
            ChartDirector::CrossShape(0.7), ChartDirector::Cross2Shape(0.1),
            ChartDirector::Cross2Shape(0.2), ChartDirector::Cross2Shape(0.3),
            ChartDirector::Cross2Shape(0.4), ChartDirector::Cross2Shape(0.5),
            ChartDirector::Cross2Shape(0.6), ChartDirector::Cross2Shape(0.7),
            ChartDirector::ArrowShape(), ChartDirector::ArrowShape(45), ChartDirector::ArrowShape(
            90, 0.5), ChartDirector::ArrowShape(135, 0.5, 0.2), ChartDirector::ArrowShape(180, 0.3,
            0.2, 0.3), ChartDirector::ArrowShape(225, 1, 0.5, 0.7), ChartDirector::ArrowShape(270,
            1, 0.5, 0.25), ChartDirector::ArrowShape(315, 0.5, 0.5, 0), ChartDirector::ArrowShape(
            30, 0.5, 0.1, 0.6), ChartDirector::ArrowShape(210, 0.5, 0.1, 0.6),
            ChartDirector::ArrowShape(330, 0.7, 0.1), ChartDirector::ArrowShape(150, 0.7, 0.1)]

        # Create a XYChart object of size 500 x 450 pixels
        c = ChartDirector::XYChart.new(500, 450)

        # Set the plotarea at (55, 40) and of size 400 x 350 pixels, with a light grey border
        # (0xc0c0c0). Turn on both horizontal and vertical grid lines with light grey color
        # (0xc0c0c0)
        c.setPlotArea(55, 40, 400, 350, -1, -1, 0xc0c0c0, 0xc0c0c0, -1)

        # Add a title to the chart using 18pt Times Bold Itatic font.
        c.addTitle("Built-in Symbols", "timesbi.ttf", 18)

        # Set the axes line width to 3 pixels
        c.xAxis().setWidth(3)
        c.yAxis().setWidth(3)

        # Ensure the ticks are at least 1 unit part (integer ticks)
        c.xAxis().setMinTickInc(1)
        c.yAxis().setMinTickInc(1)

        # Add each symbol as a separate scatter layer.
        0.upto(symbols.length - 1) do |i|
            c.addScatterLayer([i % 7 + 1.0], [(i / 7 + 1.0).to_i], "", symbols[i], 17)
        end

        # Output the chart
        send_data(c.makeChart2(ChartDirector::PNG), :type => "image/png", :disposition => "inline")

    end

end

[Ruby On Rails Version - View] app/views/templates/chartview.html.erb
<html>
<body style="margin:5px 0px 0px 5px">

<!-- Title -->
<div style="font-size:18pt; font-family:verdana; font-weight:bold">
    <%= @title %>
</div>
<hr style="border:solid 1px #000080" />

<!-- Source Code Listing Link -->
<div style="font-size:9pt; font-family:verdana; margin-bottom:1.5em">
    <%= link_to "Source Code Listing", 
        :controller => "cddemo", :action => "viewsource",
        :ctrl_file => @ctrl_file, :view_file => File.expand_path(__FILE__) %>
</div>

<!-- Create one or more IMG tags to display the demo chart(s) -->
<% 0.upto(@noOfCharts - 1) do |i| %>
    <img src="<%= url_for(:action => "getchart", :img => i) %>">
<% end %>

</body>
</html>

[Command Line Version] rubydemo/builtinsymbols.rb
#!/usr/bin/env ruby
require("chartdirector")

# Some ChartDirector built-in symbols
symbols = [ChartDirector::CircleShape, ChartDirector::GlassSphereShape,
    ChartDirector::GlassSphere2Shape, ChartDirector::SolidSphereShape, ChartDirector::SquareShape,
    ChartDirector::DiamondShape, ChartDirector::TriangleShape, ChartDirector::RightTriangleShape,
    ChartDirector::LeftTriangleShape, ChartDirector::InvertedTriangleShape,
    ChartDirector::StarShape(3), ChartDirector::StarShape(4), ChartDirector::StarShape(5),
    ChartDirector::StarShape(6), ChartDirector::StarShape(7), ChartDirector::StarShape(8),
    ChartDirector::StarShape(9), ChartDirector::StarShape(10), ChartDirector::PolygonShape(5),
    ChartDirector::Polygon2Shape(5), ChartDirector::PolygonShape(6), ChartDirector::Polygon2Shape(6
    ), ChartDirector::Polygon2Shape(7), ChartDirector::CrossShape(0.1), ChartDirector::CrossShape(
    0.2), ChartDirector::CrossShape(0.3), ChartDirector::CrossShape(0.4), ChartDirector::CrossShape(
    0.5), ChartDirector::CrossShape(0.6), ChartDirector::CrossShape(0.7),
    ChartDirector::Cross2Shape(0.1), ChartDirector::Cross2Shape(0.2), ChartDirector::Cross2Shape(0.3
    ), ChartDirector::Cross2Shape(0.4), ChartDirector::Cross2Shape(0.5), ChartDirector::Cross2Shape(
    0.6), ChartDirector::Cross2Shape(0.7), ChartDirector::ArrowShape(), ChartDirector::ArrowShape(45
    ), ChartDirector::ArrowShape(90, 0.5), ChartDirector::ArrowShape(135, 0.5, 0.2),
    ChartDirector::ArrowShape(180, 0.3, 0.2, 0.3), ChartDirector::ArrowShape(225, 1, 0.5, 0.7),
    ChartDirector::ArrowShape(270, 1, 0.5, 0.25), ChartDirector::ArrowShape(315, 0.5, 0.5, 0),
    ChartDirector::ArrowShape(30, 0.5, 0.1, 0.6), ChartDirector::ArrowShape(210, 0.5, 0.1, 0.6),
    ChartDirector::ArrowShape(330, 0.7, 0.1), ChartDirector::ArrowShape(150, 0.7, 0.1)]

# Create a XYChart object of size 500 x 450 pixels
c = ChartDirector::XYChart.new(500, 450)

# Set the plotarea at (55, 40) and of size 400 x 350 pixels, with a light grey border (0xc0c0c0).
# Turn on both horizontal and vertical grid lines with light grey color (0xc0c0c0)
c.setPlotArea(55, 40, 400, 350, -1, -1, 0xc0c0c0, 0xc0c0c0, -1)

# Add a title to the chart using 18pt Times Bold Itatic font.
c.addTitle("Built-in Symbols", "timesbi.ttf", 18)

# Set the axes line width to 3 pixels
c.xAxis().setWidth(3)
c.yAxis().setWidth(3)

# Ensure the ticks are at least 1 unit part (integer ticks)
c.xAxis().setMinTickInc(1)
c.yAxis().setMinTickInc(1)

# Add each symbol as a separate scatter layer.
0.upto(symbols.length - 1) do |i|
    c.addScatterLayer([i % 7 + 1.0], [(i / 7 + 1.0).to_i], "", symbols[i], 17)
end

# Output the chart
c.makeChart("builtinsymbols.png")