Initial working chart data labels.

This commit is contained in:
John McNamara 2017-01-22 18:13:31 +00:00
parent f6778466a4
commit 673a0e0458
24 changed files with 692 additions and 1 deletions

1
.indent.pro vendored
View File

@ -57,6 +57,7 @@
-T lxw_chart_fill
-T lxw_chart_font
-T lxw_chart_gridline
-T lxw_chart_label_position
-T lxw_chart_legend
-T lxw_chart_legend_position
-T lxw_chart_line

View File

@ -409,6 +409,41 @@ typedef enum lxw_chart_pattern_type {
LXW_CHART_PATTERN_SOLID_DIAMOND
} lxw_chart_pattern_type;
/**
* @brief Chart data label positions.
*/
typedef enum lxw_chart_label_position {
/** Series data label position: default position. */
LXW_CHART_LABEL_POSITION_DEFAULT,
/** Series data label position: center. */
LXW_CHART_LABEL_POSITION_CENTER,
/** Series data label position: right. */
LXW_CHART_LABEL_POSITION_RIGHT,
/** Series data label position: left. */
LXW_CHART_LABEL_POSITION_LEFT,
/** Series data label position: above. */
LXW_CHART_LABEL_POSITION_ABOVE,
/** Series data label position: below. */
LXW_CHART_LABEL_POSITION_BELOW,
/** Series data label position: inside base. */
LXW_CHART_LABEL_POSITION_INSIDE_BASE,
/** Series data label position: inside end. */
LXW_CHART_LABEL_POSITION_INSIDE_END,
/** Series data label position: outside end. */
LXW_CHART_LABEL_POSITION_OUTSIDE_END,
/** Series data label position: best fit. */
LXW_CHART_LABEL_POSITION_BEST_FIT
} lxw_chart_label_position;
enum lxw_chart_subtype {
LXW_CHART_SUBTYPE_NONE = 0,
@ -743,6 +778,13 @@ typedef struct lxw_chart_series {
uint8_t smooth;
uint8_t invert_if_negative;
uint8_t has_labels;
uint8_t show_value;
uint8_t show_category;
uint8_t show_name;
uint8_t label_position;
uint8_t default_label_position;
STAILQ_ENTRY (lxw_chart_series) list_pointers;
} lxw_chart_series;
@ -908,6 +950,8 @@ typedef struct lxw_chart {
lxw_chart_fill *up_bar_fill;
lxw_chart_fill *down_bar_fill;
uint8_t default_label_position;
STAILQ_ENTRY (lxw_chart) ordered_list_pointers;
STAILQ_ENTRY (lxw_chart) list_pointers;
@ -1395,6 +1439,11 @@ lxw_error chart_series_set_points(lxw_chart_series *series,
*/
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_position(lxw_chart_series *series,
uint8_t position);
/**
* @brief Set the name caption of the an axis.
*

View File

@ -2010,6 +2010,80 @@ _chart_write_invert_if_negative(lxw_chart *self, lxw_chart_series *series)
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:showVal> element.
*/
STATIC void
_chart_write_show_val(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:showVal", &attributes);
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:dLblPos> element.
*/
STATIC void
_chart_write_d_lbl_pos(lxw_chart *self, uint8_t position)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
LXW_INIT_ATTRIBUTES();
if (position == LXW_CHART_LABEL_POSITION_RIGHT)
LXW_PUSH_ATTRIBUTES_STR("val", "r");
else if (position == LXW_CHART_LABEL_POSITION_LEFT)
LXW_PUSH_ATTRIBUTES_STR("val", "l");
else if (position == LXW_CHART_LABEL_POSITION_ABOVE)
LXW_PUSH_ATTRIBUTES_STR("val", "t");
else if (position == LXW_CHART_LABEL_POSITION_BELOW)
LXW_PUSH_ATTRIBUTES_STR("val", "b");
else if (position == LXW_CHART_LABEL_POSITION_INSIDE_BASE)
LXW_PUSH_ATTRIBUTES_STR("val", "inBase");
else if (position == LXW_CHART_LABEL_POSITION_INSIDE_END)
LXW_PUSH_ATTRIBUTES_STR("val", "inEnd");
else if (position == LXW_CHART_LABEL_POSITION_OUTSIDE_END)
LXW_PUSH_ATTRIBUTES_STR("val", "outEnd");
else if (position == LXW_CHART_LABEL_POSITION_BEST_FIT)
LXW_PUSH_ATTRIBUTES_STR("val", "bestFit");
else
LXW_PUSH_ATTRIBUTES_STR("val", "ctr");
lxw_xml_empty_tag(self->file, "c:dLblPos", &attributes);
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:dLbls> element.
*/
STATIC void
_chart_write_d_lbls(lxw_chart *self, lxw_chart_series *series)
{
if (!series->has_labels)
return;
lxw_xml_start_tag(self->file, "c:dLbls", NULL);
/* Write the c:dLblPos element. */
if (series->label_position)
_chart_write_d_lbl_pos(self, series->label_position);
/* Write the c:showVal element. */
if (series->show_value)
_chart_write_show_val(self);
lxw_xml_end_tag(self->file, "c:dLbls");
}
/*
* Write the <c:size> element.
*/
@ -2218,6 +2292,9 @@ _chart_write_ser(lxw_chart *self, lxw_chart_series *series)
/* Write the char points. */
_chart_write_points(self, series);
/* Write the c:dLbls element. */
_chart_write_d_lbls(self, series);
/* Write the c:cat element. */
_chart_write_cat(self, series);
@ -2260,6 +2337,9 @@ _chart_write_xval_ser(lxw_chart *self, lxw_chart_series *series)
/* Write the char points. */
_chart_write_points(self, series);
/* Write the c:dLbls element. */
_chart_write_d_lbls(self, series);
/* Write the c:xVal element. */
_chart_write_x_val(self, series);
@ -3955,6 +4035,7 @@ _chart_initialize_area_chart(lxw_chart *self, uint8_t type)
self->grouping = LXW_GROUPING_STANDARD;
self->default_cross_between = LXW_CHART_AXIS_POSITION_ON_TICK;
self->x_axis->is_category = LXW_TRUE;
self->default_label_position = LXW_CHART_LABEL_POSITION_CENTER;
if (type == LXW_CHART_AREA_STACKED) {
self->grouping = LXW_GROUPING_STACKED;
@ -3998,6 +4079,7 @@ _chart_initialize_bar_chart(lxw_chart *self, uint8_t type)
self->x_axis->is_value = LXW_TRUE;
self->has_horiz_cat_axis = LXW_TRUE;
self->has_horiz_val_axis = LXW_FALSE;
self->default_label_position = LXW_CHART_LABEL_POSITION_OUTSIDE_END;
if (type == LXW_CHART_BAR_STACKED) {
self->grouping = LXW_GROUPING_STACKED;
@ -4029,6 +4111,7 @@ _chart_initialize_column_chart(lxw_chart *self, uint8_t type)
self->has_horiz_val_axis = LXW_FALSE;
self->x_axis->is_category = LXW_TRUE;
self->y_axis->is_value = LXW_TRUE;
self->default_label_position = LXW_CHART_LABEL_POSITION_OUTSIDE_END;
if (type == LXW_CHART_COLUMN_STACKED) {
self->grouping = LXW_GROUPING_STACKED;
@ -4059,6 +4142,7 @@ _chart_initialize_doughnut_chart(lxw_chart *self)
/* Initialize the function pointers for this chart type. */
self->write_chart_type = _chart_write_doughnut_chart;
self->write_plot_area = _chart_write_pie_plot_area;
self->default_label_position = LXW_CHART_LABEL_POSITION_BEST_FIT;
}
/*
@ -4071,6 +4155,7 @@ _chart_initialize_line_chart(lxw_chart *self)
self->grouping = LXW_GROUPING_STANDARD;
self->x_axis->is_category = LXW_TRUE;
self->y_axis->is_value = LXW_TRUE;
self->default_label_position = LXW_CHART_LABEL_POSITION_RIGHT;
/* Initialize the function pointers for this chart type. */
self->write_chart_type = _chart_write_line_chart;
@ -4086,6 +4171,7 @@ _chart_initialize_pie_chart(lxw_chart *self)
/* Initialize the function pointers for this chart type. */
self->write_chart_type = _chart_write_pie_chart;
self->write_plot_area = _chart_write_pie_plot_area;
self->default_label_position = LXW_CHART_LABEL_POSITION_BEST_FIT;
}
/*
@ -4099,6 +4185,7 @@ _chart_initialize_scatter_chart(lxw_chart *self)
self->is_scatter_chart = LXW_TRUE;
self->x_axis->is_value = LXW_TRUE;
self->y_axis->is_value = LXW_TRUE;
self->default_label_position = LXW_CHART_LABEL_POSITION_RIGHT;
if (self->type == LXW_CHART_SCATTER_STRAIGHT
|| self->type == LXW_CHART_SCATTER_SMOOTH) {
@ -4123,8 +4210,8 @@ _chart_initialize_radar_chart(lxw_chart *self, uint8_t type)
self->x_axis->major_gridlines.visible = LXW_TRUE;
self->x_axis->is_category = LXW_TRUE;
self->y_axis->is_value = LXW_TRUE;
self->y_axis->major_tick_mark = LXW_CHART_AXIS_TICK_MARK_CROSSING;
self->default_label_position = LXW_CHART_LABEL_POSITION_CENTER;
/* Initialize the function pointers for this chart type. */
self->write_chart_type = _chart_write_radar_chart;
@ -4313,6 +4400,8 @@ chart_add_series(lxw_chart *self, const char *categories, const char *values)
if (self->type == LXW_CHART_SCATTER_SMOOTH_WITH_MARKERS)
series->smooth = LXW_TRUE;
series->default_label_position = self->default_label_position;
STAILQ_INSERT_TAIL(self->series_list, series, list_pointers);
return series;
@ -4597,6 +4686,29 @@ chart_series_set_smooth(lxw_chart_series *series, uint8_t smooth)
series->smooth = smooth;
}
/*
* Turn on default data labels for a series.
*/
void
chart_series_set_labels(lxw_chart_series *series)
{
series->has_labels = LXW_TRUE;
series->show_value = LXW_TRUE;
}
/*
* Set the data labels position for a series.
*/
void
chart_series_set_labels_position(lxw_chart_series *series, uint8_t position)
{
series->has_labels = LXW_TRUE;
series->show_value = LXW_TRUE;
if (position != series->default_label_position)
series->label_position = position;
}
/*
* Set an axis caption.
*/

View File

@ -0,0 +1,46 @@
/*****************************************************************************
* 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_labels01.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 = 45848832;
chart->axis_id_2 = 47718784;
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);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,47 @@
/*****************************************************************************
* 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_labels02.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 = 47721856;
chart->axis_id_2 = 53641216;
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(series1, LXW_CHART_LABEL_POSITION_INSIDE_END);
chart_series_set_labels_position(series2, LXW_CHART_LABEL_POSITION_CENTER);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,47 @@
/*****************************************************************************
* 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_labels03.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_BAR);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 45693952;
chart->axis_id_2 = 45762816;
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(series1, 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

@ -0,0 +1,47 @@
/*****************************************************************************
* 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_labels04.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_BAR);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 47719168;
chart->axis_id_2 = 47720704;
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(series1, LXW_CHART_LABEL_POSITION_INSIDE_END);
chart_series_set_labels_position(series2, LXW_CHART_LABEL_POSITION_CENTER);
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_labels05.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_LINE);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 45678592;
chart->axis_id_2 = 45680128;
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_position(series1, LXW_CHART_LABEL_POSITION_RIGHT);
chart_series_set_labels_position(series2, LXW_CHART_LABEL_POSITION_ABOVE);
chart_series_set_labels_position(series3, LXW_CHART_LABEL_POSITION_BELOW);
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_labels06.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_LINE);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 45678592;
chart->axis_id_2 = 45680128;
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_position(series1, LXW_CHART_LABEL_POSITION_RIGHT);
chart_series_set_labels_position(series2, LXW_CHART_LABEL_POSITION_LEFT);
chart_series_set_labels_position(series3, LXW_CHART_LABEL_POSITION_CENTER);
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_labels07.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_AREA);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 45703168;
chart->axis_id_2 = 45705472;
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,51 @@
/*****************************************************************************
* 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_labels08.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_SCATTER);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 45740416;
chart->axis_id_2 = 45705856;
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,
"=Sheet1!$A$1:$A$5",
"=Sheet1!$B$1:$B$5"
);
chart_add_series(chart,
"=Sheet1!$A$1:$A$5",
"=Sheet1!$C$1:$C$5"
);
chart_series_set_labels(series1);
chart_series_set_labels_position(series1, LXW_CHART_LABEL_POSITION_RIGHT);
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_labels09.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_SCATTER);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 45740416;
chart->axis_id_2 = 45705856;
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,
"=Sheet1!$A$1:$A$5",
"=Sheet1!$B$1:$B$5"
);
lxw_chart_series *series2 = chart_add_series(chart,
"=Sheet1!$A$1:$A$5",
"=Sheet1!$C$1:$C$5"
);
chart_series_set_labels(series1);
chart_series_set_labels(series2);
chart_series_set_labels_position(series1, LXW_CHART_LABEL_POSITION_ABOVE);
chart_series_set_labels_position(series2, LXW_CHART_LABEL_POSITION_BELOW);
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_labels10.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_SCATTER);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 45740416;
chart->axis_id_2 = 45705856;
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,
"=Sheet1!$A$1:$A$5",
"=Sheet1!$B$1:$B$5"
);
lxw_chart_series *series2 = chart_add_series(chart,
"=Sheet1!$A$1:$A$5",
"=Sheet1!$C$1:$C$5"
);
chart_series_set_labels(series1);
chart_series_set_labels(series2);
chart_series_set_labels_position(series1, LXW_CHART_LABEL_POSITION_LEFT);
chart_series_set_labels_position(series2, LXW_CHART_LABEL_POSITION_CENTER);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,44 @@
###############################################################################
#
# Tests for libxlsxwriter.
#
# Copyright 2014-2017, John McNamara, jmcnamara@cpan.org
#
import base_test_class
class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
"""
Test file created with libxlsxwriter against a file created by Excel.
"""
def test_chart_data_labels01(self):
self.run_exe_test('test_chart_data_labels01')
def test_chart_data_labels02(self):
self.run_exe_test('test_chart_data_labels02')
def test_chart_data_labels03(self):
self.run_exe_test('test_chart_data_labels03')
def test_chart_data_labels04(self):
self.run_exe_test('test_chart_data_labels04')
def test_chart_data_labels05(self):
self.run_exe_test('test_chart_data_labels05')
def test_chart_data_labels06(self):
self.run_exe_test('test_chart_data_labels06')
def test_chart_data_labels07(self):
self.run_exe_test('test_chart_data_labels07')
def test_chart_data_labels08(self):
self.run_exe_test('test_chart_data_labels08')
def test_chart_data_labels09(self):
self.run_exe_test('test_chart_data_labels09')
def test_chart_data_labels10(self):
self.run_exe_test('test_chart_data_labels10')

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.