More features and tests for chart data labels.

This commit is contained in:
John McNamara 2017-01-23 00:08:25 +00:00
parent 673a0e0458
commit 9f2108feb1
32 changed files with 992 additions and 18 deletions

1
.indent.pro vendored
View File

@ -58,6 +58,7 @@
-T lxw_chart_font
-T lxw_chart_gridline
-T lxw_chart_label_position
-T lxw_chart_label_separator
-T lxw_chart_legend
-T lxw_chart_legend_position
-T lxw_chart_line

View File

@ -444,6 +444,26 @@ typedef enum lxw_chart_label_position {
LXW_CHART_LABEL_POSITION_BEST_FIT
} lxw_chart_label_position;
/**
* @brief Chart data label separator.
*/
typedef enum lxw_chart_label_separator {
/** Series data label separator: comma (the default). */
LXW_CHART_LABEL_SEPARATOR_COMMA,
/** Series data label separator: semicolon. */
LXW_CHART_LABEL_SEPARATOR_SEMICOLON,
/** Series data label separator: period. */
LXW_CHART_LABEL_SEPARATOR_PERIOD,
/** Series data label separator: newline. */
LXW_CHART_LABEL_SEPARATOR_NEWLINE,
/** Series data label separator: space. */
LXW_CHART_LABEL_SEPARATOR_SPACE
} lxw_chart_label_separator;
enum lxw_chart_subtype {
LXW_CHART_SUBTYPE_NONE = 0,
@ -778,12 +798,19 @@ typedef struct lxw_chart_series {
uint8_t smooth;
uint8_t invert_if_negative;
/* Data label parameters. */
uint8_t has_labels;
uint8_t show_value;
uint8_t show_category;
uint8_t show_name;
uint8_t show_labels_value;
uint8_t show_labels_category;
uint8_t show_labels_name;
uint8_t show_labels_leader;
uint8_t show_labels_legend;
uint8_t show_labels_percent;
uint8_t label_position;
uint8_t label_separator;
uint8_t default_label_position;
char *label_num_format;
lxw_chart_font *label_font;
STAILQ_ENTRY (lxw_chart_series) list_pointers;
@ -1441,9 +1468,28 @@ void chart_series_set_smooth(lxw_chart_series *series, uint8_t smooth);
void chart_series_set_labels(lxw_chart_series *series);
void chart_series_set_labels_options(lxw_chart_series *series,
uint8_t show_name, uint8_t show_category,
uint8_t show_value);
void chart_series_set_labels_separator(lxw_chart_series *series,
uint8_t separator);
void chart_series_set_labels_position(lxw_chart_series *series,
uint8_t position);
void chart_series_set_labels_leader_line(lxw_chart_series *series);
void chart_series_set_labels_legend(lxw_chart_series *series);
void chart_series_set_labels_percentage(lxw_chart_series *series);
void chart_series_set_labels_num_format(lxw_chart_series *series,
char *num_format);
void chart_series_set_labels_font(lxw_chart_series *series,
lxw_chart_font *font);
/**
* @brief Set the name caption of the an axis.
*

View File

@ -69,6 +69,20 @@ _chart_free_points(lxw_chart_series *series)
free(series->points);
}
/*
* Free a chart font object.
*/
STATIC void
_chart_free_font(lxw_chart_font *font)
{
if (!font)
return;
free(font->name);
free(font);
}
/*
* Free a series object.
*/
@ -82,6 +96,8 @@ _chart_series_free(lxw_chart_series *series)
free(series->line);
free(series->fill);
free(series->pattern);
free(series->label_num_format);
_chart_free_font(series->label_font);
if (series->marker) {
free(series->marker->line);
@ -112,18 +128,6 @@ _chart_init_data_cache(lxw_series_range *range)
return LXW_NO_ERROR;
}
/*
* Free a chart font object.
*/
STATIC void
_chart_free_font(lxw_chart_font *font)
{
if (!font)
return;
free(font->name);
free(font);
}
/*
* Free a chart object.
@ -2027,6 +2031,58 @@ _chart_write_show_val(lxw_chart *self)
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:showCatName> element.
*/
STATIC void
_chart_write_show_cat_name(lxw_chart *self)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
LXW_INIT_ATTRIBUTES();
LXW_PUSH_ATTRIBUTES_STR("val", "1");
lxw_xml_empty_tag(self->file, "c:showCatName", &attributes);
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:showSerName> element.
*/
STATIC void
_chart_write_show_ser_name(lxw_chart *self)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
char val[] = "1";
LXW_INIT_ATTRIBUTES();
LXW_PUSH_ATTRIBUTES_STR("val", val);
lxw_xml_empty_tag(self->file, "c:showSerName", &attributes);
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:showLeaderLines> element.
*/
STATIC void
_chart_write_show_leader_lines(lxw_chart *self)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
LXW_INIT_ATTRIBUTES();
LXW_PUSH_ATTRIBUTES_STR("val", "1");
lxw_xml_empty_tag(self->file, "c:showLeaderLines", &attributes);
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:dLblPos> element.
*/
@ -2062,6 +2118,76 @@ _chart_write_d_lbl_pos(lxw_chart *self, uint8_t position)
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:separator> element.
*/
STATIC void
_chart_write_separator(lxw_chart *self, uint8_t separator)
{
if (separator == LXW_CHART_LABEL_SEPARATOR_SEMICOLON)
lxw_xml_data_element(self->file, "c:separator", "; ", NULL);
else if (separator == LXW_CHART_LABEL_SEPARATOR_PERIOD)
lxw_xml_data_element(self->file, "c:separator", ". ", NULL);
else if (separator == LXW_CHART_LABEL_SEPARATOR_NEWLINE)
lxw_xml_data_element(self->file, "c:separator", "\n", NULL);
else if (separator == LXW_CHART_LABEL_SEPARATOR_SPACE)
lxw_xml_data_element(self->file, "c:separator", " ", NULL);
else
lxw_xml_data_element(self->file, "c:separator", ", ", NULL);
}
/*
* Write the <c:showLegendKey> element.
*/
STATIC void
_chart_write_show_legend_key(lxw_chart *self)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
LXW_INIT_ATTRIBUTES();
LXW_PUSH_ATTRIBUTES_STR("val", "1");
lxw_xml_empty_tag(self->file, "c:showLegendKey", &attributes);
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:showPercent> element.
*/
STATIC void
_chart_write_show_percent(lxw_chart *self)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
LXW_INIT_ATTRIBUTES();
LXW_PUSH_ATTRIBUTES_STR("val", "1");
lxw_xml_empty_tag(self->file, "c:showPercent", &attributes);
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:numFmt> element.
*/
STATIC void
_chart_write_label_num_fmt(lxw_chart *self, char *format)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
LXW_INIT_ATTRIBUTES();
LXW_PUSH_ATTRIBUTES_STR("formatCode", format);
LXW_PUSH_ATTRIBUTES_STR("sourceLinked", "0");
lxw_xml_empty_tag(self->file, "c:numFmt", &attributes);
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:dLbls> element.
*/
@ -2073,14 +2199,45 @@ _chart_write_d_lbls(lxw_chart *self, lxw_chart_series *series)
lxw_xml_start_tag(self->file, "c:dLbls", NULL);
/* Write the c:numFmt element. */
if (series->label_num_format)
_chart_write_label_num_fmt(self, series->label_num_format);
if (series->label_font)
_chart_write_tx_pr(self, LXW_FALSE, series->label_font);
/* Write the c:dLblPos element. */
if (series->label_position)
_chart_write_d_lbl_pos(self, series->label_position);
/* Write the c:showLegendKey element. */
if (series->show_labels_legend)
_chart_write_show_legend_key(self);
/* Write the c:showVal element. */
if (series->show_value)
if (series->show_labels_value)
_chart_write_show_val(self);
/* Write the c:showCatName element. */
if (series->show_labels_category)
_chart_write_show_cat_name(self);
/* Write the c:showSerName element. */
if (series->show_labels_name)
_chart_write_show_ser_name(self);
/* Write the c:showPercent element. */
if (series->show_labels_percent)
_chart_write_show_percent(self);
/* Write the c:separator element. */
if (series->label_separator)
_chart_write_separator(self, series->label_separator);
/* Write the c:showLeaderLines element. */
if (series->show_labels_leader)
_chart_write_show_leader_lines(self);
lxw_xml_end_tag(self->file, "c:dLbls");
}
@ -4693,7 +4850,30 @@ void
chart_series_set_labels(lxw_chart_series *series)
{
series->has_labels = LXW_TRUE;
series->show_value = LXW_TRUE;
series->show_labels_value = LXW_TRUE;
}
/*
* Set the data labels options for a series.
*/
void
chart_series_set_labels_options(lxw_chart_series *series, uint8_t show_name,
uint8_t show_category, uint8_t show_value)
{
series->has_labels = LXW_TRUE;
series->show_labels_name = show_name;
series->show_labels_category = show_category;
series->show_labels_value = show_value;
}
/*
* Set the data labels separator for a series.
*/
void
chart_series_set_labels_separator(lxw_chart_series *series, uint8_t separator)
{
series->has_labels = LXW_TRUE;
series->label_separator = separator;
}
/*
@ -4703,12 +4883,72 @@ void
chart_series_set_labels_position(lxw_chart_series *series, uint8_t position)
{
series->has_labels = LXW_TRUE;
series->show_value = LXW_TRUE;
series->show_labels_value = LXW_TRUE;
if (position != series->default_label_position)
series->label_position = position;
}
/*
* Set the data labels position for a series.
*/
void
chart_series_set_labels_leader_line(lxw_chart_series *series)
{
series->has_labels = LXW_TRUE;
series->show_labels_leader = LXW_TRUE;
}
/*
* Turn on the data labels legend for a series.
*/
void
chart_series_set_labels_legend(lxw_chart_series *series)
{
series->has_labels = LXW_TRUE;
series->show_labels_legend = LXW_TRUE;
}
/*
* Turn on the data labels percentage for a series.
*/
void
chart_series_set_labels_percentage(lxw_chart_series *series)
{
series->has_labels = LXW_TRUE;
series->show_labels_percent = LXW_TRUE;
}
/*
* Set an data labels number format.
*/
void
chart_series_set_labels_num_format(lxw_chart_series *series, char *num_format)
{
if (!num_format)
return;
/* Free any previously allocated resource. */
free(series->label_num_format);
series->label_num_format = lxw_strdup(num_format);
}
/*
* Set an data labels font.
*/
void
chart_series_set_labels_font(lxw_chart_series *series, lxw_chart_font *font)
{
if (!font)
return;
/* Free any previously allocated resource. */
_chart_free_font(series->label_font);
series->label_font = _chart_convert_font_args(font);
}
/*
* Set an axis caption.
*/

View File

@ -0,0 +1,40 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = new_workbook("test_chart_data_labels11.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_PIE);
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}
};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
chart_series_set_labels(series1);
chart_series_set_labels_position(series1, LXW_CHART_LABEL_POSITION_BEST_FIT);
chart_series_set_labels_leader_line(series1);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,40 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = new_workbook("test_chart_data_labels12.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_PIE);
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}
};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
chart_series_set_labels(series1);
chart_series_set_labels_position(series1, LXW_CHART_LABEL_POSITION_OUTSIDE_END);
chart_series_set_labels_leader_line(series1);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,40 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = new_workbook("test_chart_data_labels13.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_PIE);
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}
};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
chart_series_set_labels(series1);
chart_series_set_labels_position(series1, LXW_CHART_LABEL_POSITION_INSIDE_END);
chart_series_set_labels_leader_line(series1);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,40 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = new_workbook("test_chart_data_labels14.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_PIE);
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}
};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
chart_series_set_labels(series1);
chart_series_set_labels_position(series1, LXW_CHART_LABEL_POSITION_CENTER);
chart_series_set_labels_leader_line(series1);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,40 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = new_workbook("test_chart_data_labels15.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_DOUGHNUT);
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}
};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
chart_series_set_labels(series1);
chart_series_set_labels_position(series1, LXW_CHART_LABEL_POSITION_BEST_FIT);
chart_series_set_labels_leader_line(series1);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,43 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = new_workbook("test_chart_data_labels16.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_RADAR);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 45858816;
chart->axis_id_2 = 45860352;
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}
};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
chart_series_set_labels(series1);
chart_series_set_labels_position(series1, LXW_CHART_LABEL_POSITION_CENTER);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,53 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = new_workbook("test_chart_data_labels18.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 45740416;
chart->axis_id_2 = 45747584;
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}
};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
lxw_chart_series *series2 = chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
lxw_chart_series *series3 = chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");
chart_series_set_labels(series1);
chart_series_set_labels(series2);
chart_series_set_labels(series3);
chart_series_set_labels_options(series1, LXW_FALSE, LXW_TRUE, LXW_TRUE);
chart_series_set_labels_options(series2, LXW_FALSE, LXW_TRUE, LXW_TRUE);
chart_series_set_labels_options(series3, LXW_FALSE, LXW_TRUE, LXW_TRUE);
chart_series_set_labels_separator(series2, LXW_CHART_LABEL_SEPARATOR_SEMICOLON);
chart_series_set_labels_separator(series3, LXW_CHART_LABEL_SEPARATOR_PERIOD);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,54 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = new_workbook("test_chart_data_labels19.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 45740416;
chart->axis_id_2 = 45747584;
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}
};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
lxw_chart_series *series2 = chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
lxw_chart_series *series3 = chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");
chart_series_set_labels(series1);
chart_series_set_labels(series2);
chart_series_set_labels(series3);
chart_series_set_labels_options(series1, LXW_FALSE, LXW_TRUE, LXW_TRUE);
chart_series_set_labels_options(series2, LXW_FALSE, LXW_TRUE, LXW_TRUE);
chart_series_set_labels_options(series3, LXW_FALSE, LXW_TRUE, LXW_TRUE);
chart_series_set_labels_separator(series2, LXW_CHART_LABEL_SEPARATOR_NEWLINE);
chart_series_set_labels_separator(series3, LXW_CHART_LABEL_SEPARATOR_SPACE);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,45 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = new_workbook("test_chart_data_labels20.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 45740032;
chart->axis_id_2 = 45743104;
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}
};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");
chart_series_set_labels(series1);
chart_series_set_labels_legend(series1);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,49 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = new_workbook("test_chart_data_labels21.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_PIE);
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}
};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
lxw_chart_font font = {.name = "Consolas", .pitch_family = 49, .charset = 0, .baseline = -1};
chart_series_set_labels(series1);
chart_series_set_labels_options(series1, LXW_TRUE, LXW_TRUE, LXW_TRUE);
chart_series_set_labels_position(series1, LXW_CHART_LABEL_POSITION_INSIDE_END);
chart_series_set_labels_separator(series1, LXW_CHART_LABEL_SEPARATOR_SEMICOLON);
chart_series_set_labels_leader_line(series1);
chart_series_set_labels_legend(series1);
chart_series_set_labels_percentage(series1);
chart_series_set_labels_num_format(series1, "#,##0.00");
chart_series_set_labels_font(series1, &font);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,48 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = new_workbook("test_chart_data_labels22.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 45705856;
chart->axis_id_2 = 45740416;
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}
};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
lxw_chart_series *series2 = chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");
chart_series_set_labels(series1);
chart_series_set_labels(series2);
chart_series_set_labels_position(series2, LXW_CHART_LABEL_POSITION_INSIDE_BASE);
chart_series_set_labels_num_format(series1, "#,##0.00");
chart_series_set_labels_num_format(series2, "0.00");
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,49 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = new_workbook("test_chart_data_labels23.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 45705856;
chart->axis_id_2 = 45740416;
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}
};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
lxw_chart_series *series2 = chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");
lxw_chart_font font = {.name = "Consolas", .pitch_family = 49, .charset = 0, .baseline = -1};
chart_series_set_labels(series1);
chart_series_set_labels(series2);
chart_series_set_labels_font(series1, &font);
chart_series_set_labels_position(series2, LXW_CHART_LABEL_POSITION_INSIDE_BASE);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,50 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = new_workbook("test_chart_data_labels24.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 45937792;
chart->axis_id_2 = 45939712;
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}
};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
lxw_chart_series *series2 = chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");
lxw_chart_font font = {.name = "Consolas", .size = 12, .pitch_family = 49, .charset = 0, .baseline = -1};
chart_series_set_labels(series1);
chart_series_set_labels(series2);
chart_series_set_labels_font(series1, &font);
chart_series_set_labels_position(series2, LXW_CHART_LABEL_POSITION_INSIDE_BASE);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,52 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = new_workbook("test_chart_data_labels25.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 108652800;
chart->axis_id_2 = 108656128;
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}
};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
lxw_chart_series *series2 = chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");
lxw_chart_font font1 = {.rotation = 45, .baseline = -1};
lxw_chart_font font2 = {.rotation = -45, .baseline = -1};
chart_series_set_labels(series1);
chart_series_set_labels(series2);
chart_series_set_labels_font(series1, &font1);
chart_series_set_labels_font(series2, &font2);
chart_series_set_labels_position(series2, LXW_CHART_LABEL_POSITION_OUTSIDE_END);
chart_series_set_labels_position(series2, LXW_CHART_LABEL_POSITION_INSIDE_BASE);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -42,3 +42,47 @@ class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
def test_chart_data_labels10(self):
self.run_exe_test('test_chart_data_labels10')
def test_chart_data_labels11(self):
self.run_exe_test('test_chart_data_labels11')
def test_chart_data_labels12(self):
self.run_exe_test('test_chart_data_labels12')
def test_chart_data_labels13(self):
self.run_exe_test('test_chart_data_labels13')
def test_chart_data_labels14(self):
self.run_exe_test('test_chart_data_labels14')
def test_chart_data_labels15(self):
self.run_exe_test('test_chart_data_labels15')
def test_chart_data_labels16(self):
self.run_exe_test('test_chart_data_labels16')
# Stock chart.
def test_chart_data_labels18(self):
self.run_exe_test('test_chart_data_labels18')
def test_chart_data_labels19(self):
self.run_exe_test('test_chart_data_labels19')
def test_chart_data_labels20(self):
self.run_exe_test('test_chart_data_labels20')
def test_chart_data_labels21(self):
self.run_exe_test('test_chart_data_labels21')
def test_chart_data_labels22(self):
self.run_exe_test('test_chart_data_labels22')
def test_chart_data_labels23(self):
self.run_exe_test('test_chart_data_labels23')
def test_chart_data_labels24(self):
self.run_exe_test('test_chart_data_labels24')
def test_chart_data_labels25(self):
self.run_exe_test('test_chart_data_labels25')

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.