}
if (proc->barchart)
chart_item_submit
- (barchart_create (pt->vars, pt->n_vars, _("Count"), pt->entries, pt->n_entries));
+ (barchart_create (pt->vars, pt->n_vars, _("Count"), false, pt->entries, pt->n_entries));
}
/* Free output and prepare for next split file. */
struct freq **slices = pick_cat_counts_ptr (bar, frq_tab, &n_slices);
chart_item_submit (barchart_create (var, 1,
- (bar->y_scale == FRQ_FREQ) ? _("Count") : _("Percent"),
+ (bar->y_scale == FRQ_FREQ) ? _("Count") : _("Percent"),
+ (bar->y_scale == FRQ_PERCENT),
slices, n_slices));
free (slices);
}
ag_func[cmd->agr].description);
chart_item_submit (barchart_create (cmd->by_var, cmd->n_by_vars,
- ds_cstr (&label),
+ ds_cstr (&label), false,
freqs, n_freqs));
ds_destroy (&label);
/* PSPP - a program for statistical analysis.
- Copyright (C) 2015 Free Software Foundation, Inc.
+ Copyright (C) 2015, 2016 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
xrchart_write_ylabel (cr, geom, bc->ylabel);
xrchart_write_xlabel (cr, geom, chart_item_get_title (chart_item));
- xrchart_write_yscale (cr, geom, 0, bc->largest);
+ if (bc->percent)
+ xrchart_write_yscale (cr, geom, 0, bc->largest * 100.0 / bc->total_count );
+ else
+ xrchart_write_yscale (cr, geom, 0, bc->largest);
const double abscale = geom->axis[SCALE_ABSCISSA].data_max - geom->axis[SCALE_ABSCISSA].data_min;
const double width = abscale / (double) (bc->n_nzcats + bc->n_pcats);
for (i = 0; i < bc->n_nzcats; i++)
{
double height = geom->axis[SCALE_ORDINATE].scale * bc->cats[i]->count;
+ if (bc->percent)
+ height *= 100.0 / bc->total_count ;
if (prev && !value_equal (prev, &bc->cats[i]->values[0], bc->widths[0]))
{
*/
struct chart_item *
barchart_create (const struct variable **var, int n_vars,
- const char *ylabel,
+ const char *ylabel, bool percent,
struct freq *const *cats, int n_cats)
{
struct barchart *bar;
assert (n_vars >= 1);
bar = xzalloc (sizeof *bar);
+ bar->percent = percent;
bar->var = var;
bar->n_vars = n_vars;
bar->n_nzcats = n_cats;
if (0 == compare_freq_2level_ptr_3way (&foo, &c, bar))
{
foo->count += c->count;
+ bar->total_count += c->count;
if (foo->count > bar->largest)
bar->largest = foo->count;
if (c->count > bar->largest)
bar->largest = aggregated_freq->count;
+ bar->total_count += c->count;
bar->cats[x++] = aggregated_freq;
}
}
{
struct chart_item chart_item;
+ /* Should the chart be displayed as percentages */
+ bool percent;
+
/* The categories */
struct freq **cats;
/* The largest count of all the categories */
double largest;
+ /* The sum of all the counts */
+ double total_count;
+
/* The label for the ordinate (vertical axis) */
char *ylabel;
struct freq;
struct chart_item *barchart_create (const struct variable **, int n_vars,
- const char *ylabel,
+ const char *ylabel, bool percent,
struct freq *const *, int n_cats);
\f
/* This boilerplate for barchart, a subclass of chart_item, was