Add chart trendlines.

This commit is contained in:
John McNamara 2017-01-29 02:01:55 +00:00
parent 29d52da15b
commit 27ebef50eb
36 changed files with 1361 additions and 8 deletions

1
.indent.pro vendored
View File

@ -73,6 +73,7 @@
-T lxw_chart_point
-T lxw_chart_series
-T lxw_chart_title
-T lxw_chart_trendline_type
-T lxw_chart_type
-T lxw_col_options
-T lxw_col_t

View File

@ -832,6 +832,29 @@ typedef struct lxw_series_error_bars {
} lxw_series_error_bars;
/**
* @brief Series trendline/regression types.
*/
typedef enum lxw_chart_trendline_type {
/** Trendline type: Linear. */
LXW_CHART_TRENDLINE_TYPE_LINEAR,
/** Trendline type: Logarithm. */
LXW_CHART_TRENDLINE_TYPE_LOG,
/** Trendline type: Polynomial. */
LXW_CHART_TRENDLINE_TYPE_POLY,
/** Trendline type: Power. */
LXW_CHART_TRENDLINE_TYPE_POWER,
/** Trendline type: Exponential. */
LXW_CHART_TRENDLINE_TYPE_EXP,
/** Trendline type: Moving Average. */
LXW_CHART_TRENDLINE_TYPE_AVERAGE
} lxw_chart_trendline_type;
/**
* @brief Struct to represent an Excel chart data series.
*
@ -871,6 +894,20 @@ typedef struct lxw_chart_series {
lxw_series_error_bars *x_error_bars;
lxw_series_error_bars *y_error_bars;
uint8_t has_trendline;
uint8_t has_trendline_forecast;
uint8_t has_trendline_equation;
uint8_t has_trendline_r_squared;
uint8_t has_trendline_intercept;
uint8_t trendline_type;
uint8_t trendline_value;
double trendline_forward;
double trendline_backward;
uint8_t trendline_value_type;
char *trendline_name;
lxw_chart_line *trendline_line;
double trendline_intercept;
STAILQ_ENTRY (lxw_chart_series) list_pointers;
} lxw_chart_series;
@ -1758,6 +1795,24 @@ void chart_series_set_labels_num_format(lxw_chart_series *series,
void chart_series_set_labels_font(lxw_chart_series *series,
lxw_chart_font *font);
void chart_series_set_trendline(lxw_chart_series *series, uint8_t type,
uint8_t value);
void chart_series_set_trendline_forecast(lxw_chart_series *series,
double forward, double backward);
void chart_series_set_trendline_equation(lxw_chart_series *series);
void chart_series_set_trendline_r_squared(lxw_chart_series *series);
void chart_series_set_trendline_intercept(lxw_chart_series *series,
double intercept);
void chart_series_set_trendline_name(lxw_chart_series *series, char *name);
void chart_series_set_trendline_line(lxw_chart_series *series,
lxw_chart_line *line);
/**
* Set the X or Y error bars for a chart series.
*

View File

@ -120,6 +120,9 @@ _chart_series_free(lxw_chart_series *series)
free(series->y_error_bars);
}
free(series->trendline_line);
free(series->trendline_name);
free(series);
}
@ -2108,10 +2111,9 @@ _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_PUSH_ATTRIBUTES_STR("val", "1");
lxw_xml_empty_tag(self->file, "c:showSerName", &attributes);
@ -2293,6 +2295,233 @@ _chart_write_d_lbls(lxw_chart *self, lxw_chart_series *series)
lxw_xml_end_tag(self->file, "c:dLbls");
}
/*
* Write the <c:intercept> element.
*/
STATIC void
_chart_write_intercept(lxw_chart *self, double value)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
LXW_INIT_ATTRIBUTES();
LXW_PUSH_ATTRIBUTES_DBL("val", value);
lxw_xml_empty_tag(self->file, "c:intercept", &attributes);
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:dispRSqr> element.
*/
STATIC void
_chart_write_disp_rsqr(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:dispRSqr", &attributes);
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:trendlineLbl> element.
*/
STATIC void
_chart_write_trendline_lbl(lxw_chart *self)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
lxw_xml_start_tag(self->file, "c:trendlineLbl", NULL);
lxw_xml_empty_tag(self->file, "c:layout", NULL);
LXW_INIT_ATTRIBUTES();
LXW_PUSH_ATTRIBUTES_STR("formatCode", "General");
LXW_PUSH_ATTRIBUTES_INT("sourceLinked", 0);
lxw_xml_empty_tag(self->file, "c:numFmt", &attributes);
lxw_xml_end_tag(self->file, "c:trendlineLbl");
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:dispEq> element.
*/
STATIC void
_chart_write_disp_eq(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:dispEq", &attributes);
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:period> element.
*/
STATIC void
_chart_write_period(lxw_chart *self, uint8_t value)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
LXW_INIT_ATTRIBUTES();
LXW_PUSH_ATTRIBUTES_INT("val", value);
lxw_xml_empty_tag(self->file, "c:period", &attributes);
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:forward> element.
*/
STATIC void
_chart_write_forward(lxw_chart *self, double value)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
LXW_INIT_ATTRIBUTES();
LXW_PUSH_ATTRIBUTES_DBL("val", value);
lxw_xml_empty_tag(self->file, "c:forward", &attributes);
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:backward> element.
*/
STATIC void
_chart_write_backward(lxw_chart *self, double value)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
LXW_INIT_ATTRIBUTES();
LXW_PUSH_ATTRIBUTES_DBL("val", value);
lxw_xml_empty_tag(self->file, "c:backward", &attributes);
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:name> element.
*/
STATIC void
_chart_write_name(lxw_chart *self, char *name)
{
lxw_xml_data_element(self->file, "c:name", name, NULL);
}
/*
* Write the <c:trendlineType> element.
*/
STATIC void
_chart_write_trendline_type(lxw_chart *self, uint8_t type)
{
struct xml_attribute_list attributes;
struct xml_attribute *attribute;
LXW_INIT_ATTRIBUTES();
if (type == LXW_CHART_TRENDLINE_TYPE_LOG)
LXW_PUSH_ATTRIBUTES_STR("val", "log");
else if (type == LXW_CHART_TRENDLINE_TYPE_POLY)
LXW_PUSH_ATTRIBUTES_STR("val", "poly");
else if (type == LXW_CHART_TRENDLINE_TYPE_POWER)
LXW_PUSH_ATTRIBUTES_STR("val", "power");
else if (type == LXW_CHART_TRENDLINE_TYPE_EXP)
LXW_PUSH_ATTRIBUTES_STR("val", "exp");
else if (type == LXW_CHART_TRENDLINE_TYPE_AVERAGE)
LXW_PUSH_ATTRIBUTES_STR("val", "movingAvg");
else
LXW_PUSH_ATTRIBUTES_STR("val", "linear");
lxw_xml_empty_tag(self->file, "c:trendlineType", &attributes);
LXW_FREE_ATTRIBUTES();
}
/*
* Write the <c:trendline> element.
*/
STATIC void
_chart_write_trendline(lxw_chart *self, lxw_chart_series *series)
{
if (!series->has_trendline)
return;
lxw_xml_start_tag(self->file, "c:trendline", NULL);
/* Write the c:name element. */
if (series->trendline_name)
_chart_write_name(self, series->trendline_name);
/* Write the c:spPr element. */
_chart_write_sp_pr(self, series->trendline_line, NULL, NULL);
/* Write the c:trendlineType element. */
_chart_write_trendline_type(self, series->trendline_type);
/* Write the c:order element. */
if (series->trendline_type == LXW_CHART_TRENDLINE_TYPE_POLY
&& series->trendline_value >= 2) {
_chart_write_order(self, series->trendline_value);
}
/* Write the c:period element. */
if (series->trendline_type == LXW_CHART_TRENDLINE_TYPE_AVERAGE
&& series->trendline_value >= 2) {
_chart_write_period(self, series->trendline_value);
}
if (series->has_trendline_forecast) {
/* Write the c:forward element. */
_chart_write_forward(self, series->trendline_forward);
/* Write the c:backward element. */
_chart_write_backward(self, series->trendline_backward);
}
/* Write the c:intercept element. */
if (series->has_trendline_intercept)
_chart_write_intercept(self, series->trendline_intercept);
/* Write the c:dispRSqr element. */
if (series->has_trendline_r_squared)
_chart_write_disp_rsqr(self);
if (series->has_trendline_equation) {
/* Write the c:dispEq element. */
_chart_write_disp_eq(self);
/* Write the c:trendlineLbl element. */
_chart_write_trendline_lbl(self);
}
lxw_xml_end_tag(self->file, "c:trendline");
}
/*
* Write the <c:val> element.
*/
@ -2501,10 +2730,9 @@ _chart_write_marker_value(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_PUSH_ATTRIBUTES_STR("val", "1");
lxw_xml_empty_tag(self->file, "c:marker", &attributes);
@ -2655,6 +2883,9 @@ _chart_write_ser(lxw_chart *self, lxw_chart_series *series)
/* Write the c:dLbls element. */
_chart_write_d_lbls(self, series);
/* Write the c:trendline element. */
_chart_write_trendline(self, series);
/* Write the c:errBars element. */
_chart_write_error_bars(self, series);
@ -2704,6 +2935,9 @@ _chart_write_xval_ser(lxw_chart *self, lxw_chart_series *series)
/* Write the c:dLbls element. */
_chart_write_d_lbls(self, series);
/* Write the c:trendline element. */
_chart_write_trendline(self, series);
/* Write the c:errBars element. */
_chart_write_error_bars(self, series);
@ -2937,10 +3171,9 @@ _chart_write_auto(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_PUSH_ATTRIBUTES_STR("val", "1");
lxw_xml_empty_tag(self->file, "c:auto", &attributes);
@ -5177,6 +5410,153 @@ chart_series_set_labels_font(lxw_chart_series *series, lxw_chart_font *font)
series->label_font = _chart_convert_font_args(font);
}
/*
* Set the trendline for a chart series.
*/
void
chart_series_set_trendline(lxw_chart_series *series, uint8_t type,
uint8_t value)
{
if (type == LXW_CHART_TRENDLINE_TYPE_POLY
|| type == LXW_CHART_TRENDLINE_TYPE_POLY) {
if (value < 2) {
LXW_WARN("chart_series_set_trendline(): order/period value must "
"be >= 2 for Polynomial and Moving Average types");
return;
}
series->trendline_value_type = type;
}
series->has_trendline = LXW_TRUE;
series->trendline_type = type;
series->trendline_value = value;
}
/*
* Set the trendline forecast for a chart series.
*/
void
chart_series_set_trendline_forecast(lxw_chart_series *series, double forward,
double backward)
{
if (!series->has_trendline) {
LXW_WARN("chart_series_set_trendline_forecast(): trendline type "
"must be set first using chart_series_set_trendline()");
return;
}
if (series->trendline_type == LXW_CHART_TRENDLINE_TYPE_AVERAGE) {
LXW_WARN("chart_series_set_trendline(): forecast isn't available "
"in Excel for a Moving Average trendline");
return;
}
series->has_trendline_forecast = LXW_TRUE;
series->trendline_forward = forward;
series->trendline_backward = backward;
}
/*
* Display the equation for a series trendline.
*/
void
chart_series_set_trendline_equation(lxw_chart_series *series)
{
if (!series->has_trendline) {
LXW_WARN("chart_series_set_trendline_equation(): trendline type "
"must be set first using chart_series_set_trendline()");
return;
}
if (series->trendline_type == LXW_CHART_TRENDLINE_TYPE_AVERAGE) {
LXW_WARN("chart_series_set_trendline_equation(): equation isn't "
"available in Excel for a Moving Average trendline");
return;
}
series->has_trendline_equation = LXW_TRUE;
}
/*
* Display the R squared value for a series trendline.
*/
void
chart_series_set_trendline_r_squared(lxw_chart_series *series)
{
if (!series->has_trendline) {
LXW_WARN("chart_series_set_trendline_r_squared(): trendline type "
"must be set first using chart_series_set_trendline()");
return;
}
if (series->trendline_type == LXW_CHART_TRENDLINE_TYPE_AVERAGE) {
LXW_WARN("chart_series_set_trendline_r_squared(): R squared isn't "
"available in Excel for a Moving Average trendline");
return;
}
series->has_trendline_r_squared = LXW_TRUE;
}
/*
* Set the trendline intercept for a chart series.
*/
void
chart_series_set_trendline_intercept(lxw_chart_series *series,
double intercept)
{
if (!series->has_trendline) {
LXW_WARN("chart_series_set_trendline_intercept(): trendline type "
"must be set first using chart_series_set_trendline()");
return;
}
if (series->trendline_type != LXW_CHART_TRENDLINE_TYPE_EXP
&& series->trendline_type != LXW_CHART_TRENDLINE_TYPE_LINEAR
&& series->trendline_type != LXW_CHART_TRENDLINE_TYPE_POLY) {
LXW_WARN("chart_series_set_trendline_intercept(): intercept is only "
"available in Excel for Exponential, Linear and Polynomial "
"trendline types");
return;
}
series->has_trendline_intercept = LXW_TRUE;
series->trendline_intercept = intercept;
}
/*
* Set a line type for a series trendline.
*/
void
chart_series_set_trendline_name(lxw_chart_series *series, char *name)
{
if (!name)
return;
/* Free any previously allocated resource. */
free(series->trendline_name);
series->trendline_name = lxw_strdup(name);
}
/*
* Set a line type for a series trendline.
*/
void
chart_series_set_trendline_line(lxw_chart_series *series,
lxw_chart_line *line)
{
if (!line)
return;
/* Free any previously allocated resource. */
free(series->trendline_line);
series->trendline_line = _chart_convert_line_args(line);
}
/*
* Set the error bars and type for a chart series.
*/
@ -5686,7 +6066,7 @@ chart_legend_delete_series(lxw_chart *self, int16_t delete_series[])
if (delete_series == NULL)
return LXW_ERROR_NULL_PARAMETER_IGNORED;
while (delete_series[count] > 0)
while (delete_series[count] >= 0)
count++;
if (count == 0)

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_format08.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 = 46164608;
chart->axis_id_2 = 46176128;
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 *series = 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_trendline(series, LXW_CHART_TRENDLINE_TYPE_LINEAR, 0);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,55 @@
/*****************************************************************************
* 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_format10.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 = 54795648;
chart->axis_id_2 = 56296960;
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 *series = 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"
);
lxw_chart_line line = {.color = LXW_COLOR_RED,
.width = 1,
.dash_type = LXW_CHART_LINE_DASH_LONG_DASH};
chart_series_set_trendline(series, LXW_CHART_TRENDLINE_TYPE_LINEAR, 0);
chart_series_set_trendline_line(series, &line);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,57 @@
/*****************************************************************************
* 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_format11.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 = 50664576;
chart->axis_id_2 = 50666496;
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 *series = 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"
);
lxw_chart_line line = {.color = LXW_COLOR_RED,
.width = 1,
.dash_type = LXW_CHART_LINE_DASH_LONG_DASH};
chart_series_set_trendline(series, LXW_CHART_TRENDLINE_TYPE_POLY, 2);
chart_series_set_trendline_line(series, &line);
chart_series_set_trendline_name(series, "My trend name");
chart_series_set_trendline_forecast(series, 0.5, 0.5);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,56 @@
/*****************************************************************************
* 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_format12.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 = 54794880;
chart->axis_id_2 = 56296576;
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 *series = 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"
);
lxw_chart_line line = {.color = LXW_COLOR_RED,
.width = 1,
.dash_type = LXW_CHART_LINE_DASH_LONG_DASH};
chart_series_set_trendline(series, LXW_CHART_TRENDLINE_TYPE_AVERAGE, 2);
chart_series_set_trendline_line(series, &line);
chart_series_set_trendline_forecast(series, 0.5, 0.5);
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_format13.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 = 51785088;
chart->axis_id_2 = 51804032;
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 *series = 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(series);
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_format14.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 = 51819264;
chart->axis_id_2 = 52499584;
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 *series = 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(series);
chart_series_set_labels_options(series, LXW_TRUE, LXW_TRUE, LXW_TRUE);
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_format15.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 = 42401792;
chart->axis_id_2 = 42403712;
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 *series = 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_trendline(series, LXW_CHART_TRENDLINE_TYPE_LINEAR, 0);
int16_t names[] = {2, 0, -1};
chart_legend_delete_series(chart, names);
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_format16.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 = 43943040;
chart->axis_id_2 = 44287488;
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 *series = 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(series);
chart_series_set_labels_options(series, LXW_TRUE, LXW_TRUE, LXW_TRUE);
chart_series_set_labels_position(series, LXW_CHART_LABEL_POSITION_CENTER);
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_format19.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN_STACKED);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 56127488;
chart->axis_id_2 = 57455360;
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);
chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
lxw_chart_series *series = chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");
chart_series_set_labels(series);
chart_series_set_labels_position(series, LXW_CHART_LABEL_POSITION_INSIDE_BASE);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,59 @@
/*****************************************************************************
* 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_format20.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_chart *chart1 = workbook_add_chart(workbook, LXW_CHART_LINE);
lxw_chart *chart2 = workbook_add_chart(workbook, LXW_CHART_LINE);
/* For testing, copy the randomly generated axis ids in the target file. */
chart1->axis_id_1 = 80553856;
chart1->axis_id_2 = 80555392;
chart2->axis_id_1 = 84583936;
chart2->axis_id_2 = 84585856;
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(chart1, NULL, "=Sheet1!$B$1:$B$5");
chart_add_series(chart1, NULL, "=Sheet1!$C$1:$C$5");
lxw_chart_series *series2 = chart_add_series(chart2, NULL, "=Sheet1!$B$1:$B$5");
chart_add_series(chart2, NULL, "=Sheet1!$C$1:$C$5");
lxw_chart_line line = {.color = LXW_COLOR_RED,
.dash_type = LXW_CHART_LINE_DASH_DASH};
chart_series_set_trendline(series1, LXW_CHART_TRENDLINE_TYPE_LINEAR, 0);
chart_series_set_trendline_line(series1, &line);
chart_series_set_trendline(series2, LXW_CHART_TRENDLINE_TYPE_LINEAR, 0);
chart_series_set_trendline_line(series2, &line);
worksheet_insert_chart(worksheet, CELL("E9"), chart1);
worksheet_insert_chart(worksheet, CELL("E25"), chart2);
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_format26.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 = 108652416;
chart->axis_id_2 = 108655744;
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 *series = 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_trendline(series, LXW_CHART_TRENDLINE_TYPE_LINEAR, 0);
chart_series_set_trendline_equation(series);
int16_t names[] = {2, 0, -1};
chart_legend_delete_series(chart, names);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,58 @@
/*****************************************************************************
* 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_format27.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 = 108645376;
chart->axis_id_2 = 108655360;
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 *series = 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"
);
lxw_chart_line line = {.color = LXW_COLOR_RED,
.width = 1,
.dash_type = LXW_CHART_LINE_DASH_LONG_DASH};
chart_series_set_trendline(series, LXW_CHART_TRENDLINE_TYPE_POLY, 2);
chart_series_set_trendline_line(series, &line);
chart_series_set_trendline_name(series, "My trend name");
chart_series_set_trendline_forecast(series, 0.5, 0.5);
chart_series_set_trendline_equation(series);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,55 @@
/*****************************************************************************
* 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_format28.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 = 108645376;
chart->axis_id_2 = 108655360;
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 *series = 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_trendline(series, LXW_CHART_TRENDLINE_TYPE_LINEAR, 0);
chart_series_set_trendline_equation(series);
chart_series_set_trendline_r_squared(series);
int16_t names[] = {0, 2, -1};
chart_legend_delete_series(chart, names);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,59 @@
/*****************************************************************************
* 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_format29.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 = 108652416;
chart->axis_id_2 = 108655744;
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 *series = 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"
);
lxw_chart_line line = {.color = LXW_COLOR_RED,
.width = 1,
.dash_type = LXW_CHART_LINE_DASH_LONG_DASH};
chart_series_set_trendline(series, LXW_CHART_TRENDLINE_TYPE_POLY, 2);
chart_series_set_trendline_line(series, &line);
chart_series_set_trendline_name(series, "My trend name");
chart_series_set_trendline_forecast(series, 0.5, 0.5);
chart_series_set_trendline_equation(series);
chart_series_set_trendline_r_squared(series);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,56 @@
/*****************************************************************************
* 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_format30.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 = 108652416;
chart->axis_id_2 = 108655744;
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 *series = 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_trendline(series, LXW_CHART_TRENDLINE_TYPE_LINEAR, 0);
chart_series_set_trendline_equation(series);
chart_series_set_trendline_r_squared(series);
chart_series_set_trendline_intercept(series, 0.8);
int16_t names[] = {0, 2, -1};
chart_legend_delete_series(chart, names);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,60 @@
/*****************************************************************************
* 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_format31.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 = 115443200;
chart->axis_id_2 = 115459200;
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 *series = 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"
);
lxw_chart_line line = {.color = LXW_COLOR_RED,
.width = 1,
.dash_type = LXW_CHART_LINE_DASH_LONG_DASH};
chart_series_set_trendline(series, LXW_CHART_TRENDLINE_TYPE_POLY, 2);
chart_series_set_trendline_line(series, &line);
chart_series_set_trendline_name(series, "My trend name");
chart_series_set_trendline_forecast(series, 0.5, 0.5);
chart_series_set_trendline_equation(series);
chart_series_set_trendline_r_squared(series);
chart_series_set_trendline_intercept(series, 1.5);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -34,12 +34,35 @@ class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
def test_chart_format07(self):
self.run_exe_test('test_chart_format07')
def test_chart_format08(self):
self.run_exe_test('test_chart_format08')
def test_chart_format09(self):
self.run_exe_test('test_chart_format09')
def test_chart_format10(self):
self.run_exe_test('test_chart_format10')
def test_chart_format11(self):
self.run_exe_test('test_chart_format11')
def test_chart_format12(self):
self.run_exe_test('test_chart_format12')
def test_chart_format13(self):
self.run_exe_test('test_chart_format13')
def test_chart_format14(self):
self.run_exe_test('test_chart_format14')
def test_chart_format14(self):
self.run_exe_test('test_chart_format14')
def test_chart_format15(self):
self.run_exe_test('test_chart_format15')
def test_chart_format16(self):
self.run_exe_test('test_chart_format16')
def test_chart_format17(self):
self.run_exe_test('test_chart_format17')
@ -47,6 +70,12 @@ class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
def test_chart_format18(self):
self.run_exe_test('test_chart_format18')
def test_chart_format19(self):
self.run_exe_test('test_chart_format19')
def test_chart_format20(self):
self.run_exe_test('test_chart_format20')
def test_chart_format21(self):
self.run_exe_test('test_chart_format21')
@ -61,3 +90,21 @@ class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
def test_chart_format25(self):
self.run_exe_test('test_chart_format25')
def test_chart_format26(self):
self.run_exe_test('test_chart_format26')
def test_chart_format27(self):
self.run_exe_test('test_chart_format27')
def test_chart_format28(self):
self.run_exe_test('test_chart_format28')
def test_chart_format29(self):
self.run_exe_test('test_chart_format29')
def test_chart_format30(self):
self.run_exe_test('test_chart_format30')
def test_chart_format31(self):
self.run_exe_test('test_chart_format31')

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.

Binary file not shown.

Binary file not shown.