Chart-ECharts
view release on metacpan or search on metacpan
lib/Chart/ECharts.pm view on Meta::CPAN
height => undef,
id => ('chart_' . get_random_id()),
locale => 'en',
options => {},
renderer => 'canvas',
responsive => 0,
series => [],
styles => ['min-width:auto', 'min-height:300px'],
theme => 'white',
vertical => 0,
width => undef,
xAxis => [],
yAxis => [],
init_method => 'event',
init_event => 'load',
@_
);
my $self = {%params};
$self->{js} = {};
return bless $self, $class;
}
sub chart_id { shift->{id} }
sub init_function { join '_', 'init', shift->{id} }
sub set_options {
my ($self, %options) = @_;
$self->{options} = {%{$self->{options}}, %options};
}
sub set_option {
Carp::carp 'DEPRECATED use $chart->set_options(%params)';
shift->set_options(@_);
}
sub set_option_item {
my ($self, $name, $params) = @_;
$self->{options}->{$name} = $params;
}
sub set_title {
my ($self, %params) = @_;
$self->set_options(title => \%params);
}
sub set_tooltip {
my ($self, %params) = @_;
$self->set_options(tooltip => \%params);
}
sub set_toolbox {
my ($self, %params) = @_;
$self->set_options(toolbox => \%params);
}
sub set_legend {
my ($self, %params) = @_;
$self->set_options(legend => \%params);
}
sub set_timeline {
my ($self, %params) = @_;
$self->set_options(timeline => \%params);
}
sub set_data_zoom {
my ($self, %params) = @_;
$self->set_options(dataZoom => \%params);
}
sub add_data_zoom {
my ($self, %params) = @_;
$self->{options}->{dataZoom} //= [];
push @{$self->{options}}, \%params;
}
sub get_random_id {
return sha1_hex(join('', time, rand));
}
sub set_event {
my ($self, $event, $callback) = @_;
$self->{events}->{$event} = $callback;
}
sub add_script {
my ($self, $script) = @_;
push @{$self->{scripts}}, $script;
}
sub on { shift->set_event(@_) }
sub set_xAxis {
my ($self, %axis) = @_;
$self->{xAxis} = \%axis;
}
sub add_xAxis {
my ($self, %axis) = @_;
push @{$self->{xAxis}}, \%axis;
}
sub set_yAxis {
my ($self, %axis) = @_;
$self->{yAxis} = \%axis;
}
sub add_yAxis {
my ($self, %axis) = @_;
push @{$self->{yAxis}}, \%axis;
}
sub add_series {
my ($self, %series) = @_;
push @{$self->{series}}, \%series;
lib/Chart/ECharts.pm view on Meta::CPAN
$chart->set_yAxis(
splitLine => {
lineStyle => {
type => 'dashed'
}
}
);
=item $chart->add_series(%series)
Add single series (see Apache ECharts documentations L<https://echarts.apache.org/en/option.html#series>).
$chart->add_series(
name => 'series_name',
type => 'bar',
data => [120, 200, 150, 80, 70, 110, 130]
);
=item $chart->add_dataset(%dataset)
Add dataset (see Apache ECharts documentations L<https://echarts.apache.org/en/option.html#dataset>).
$chart->add_dataset(
source => [
['product', '2015', '2016', '2017'],
['Matcha Latte', 43.3, 85.8, 93.7],
['Milk Tea', 83.1, 73.4, 55.1],
['Cheese Cocoa', 86.4, 65.2, 82.5],
['Walnut Brownie', 72.4, 53.9, 39.1]
]
);
=item $chart->js($expression)
Embed arbritaty JS code in chart options.
$chart->set_tooltip(
valueFormatter => $chart->js( q{(value) => '$' + Math.round(value)} )
);
=back
=head3 OPTION HELPERS
=over
=item $chart->set_title(%params)
Set the chart title
=item $chart->set_toolbox(%params)
Set the chart toolbox
=item $chart->set_tooltip(%params)
Set the chart tooltip
=item $chart->set_legend(%params)
Set the chart legend
=item $chart->set_timeline(%params)
Set the chart timeline
=item $chart->set_data_zoom(%params)
Set the chart data zoom
=item $chart->add_data_zoom(%params)
Add the chart data zoom
=back
=head3 PROPERTIES
=over
=item $chart->xAxis
Return X axis.
=item $chart->yAxis
Return Y axis.
=item $chart->series
Return chart series.
=item $chart->default_options
Return chart default options.
=item $chart->options
Return all chart options.
=item $chart->axies
Return X and Y axies.
=back
=head3 RENDERS
=over
=item $chart->render_script(%params)
Render the chart in JS.
my $script = $chart->render_script;
=item $chart->render_html(%params)
Render the chart in HTML including the output of L<render_script> with a C<div> container.
( run in 0.420 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )