Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add support for Chart date axes #91

Open
4 tasks
jmcnamara opened this issue Jan 12, 2017 · 3 comments
Open
4 tasks

Feature request: Add support for Chart date axes #91

jmcnamara opened this issue Jan 12, 2017 · 3 comments
Assignees
Milestone

Comments

@jmcnamara
Copy link
Owner

jmcnamara commented Jan 12, 2017

Add functionality like Python XlsxWriter Data Axes.

See http://xlsxwriter.readthedocs.io/working_with_charts.html#date-category-axes

  • Add date axis
  • Add date min and max
  • Add minor_unit_type
  • Add major_unit_type
  • Difficulty: 2 (Easy 1 - 5 Hard)
  • Priority: 2 (High 1 - 5 Low)

Add +1 as a comment to vote for this feature and to get an update when it is implemented.

@jmcnamara jmcnamara added this to the Phase3 milestone Jan 12, 2017
@jmcnamara jmcnamara self-assigned this Jan 12, 2017
@ragundo
Copy link

ragundo commented Feb 25, 2017

+1
Needed for daily/month/year reports generation

@ale275
Copy link

ale275 commented Feb 26, 2017

+1
perfect for report and trend analysis

@jmcnamara
Copy link
Owner Author

jmcnamara commented Feb 27, 2017

Hi,

Note, it is currently possible to use an implicit date axis by using date input data for the X-axis, see the example below. This Feature Request is mainly to add an explicit chart date axis option (like Excel) to enable max and min values and a few other features. Also note, the max and min is also currently available if you use a scatter chart (although the units won't be clear).

Example:

#include "xlsxwriter.h"

/* Create a worksheet with a chart. */
int main() {

    lxw_workbook  *workbook  = new_workbook("chart_date.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);


    /* Add an Excel date format. */
    lxw_format *date_format = workbook_add_format(workbook);
    format_set_num_format(date_format, "yyyy-mm-dd");

    /* Widen the first column to make the text clearer. */
    worksheet_set_column(worksheet, 0, 0, 20, NULL);

    /* Write some data for the chart. */
    lxw_datetime datetime1 = {.year = 2016, .month = 1, .day = 13};
    lxw_datetime datetime2 = {.year = 2016, .month = 1, .day = 14};
    lxw_datetime datetime3 = {.year = 2016, .month = 1, .day = 15};
    lxw_datetime datetime4 = {.year = 2016, .month = 1, .day = 16};
    lxw_datetime datetime5 = {.year = 2016, .month = 1, .day = 17};
    lxw_datetime datetime6 = {.year = 2016, .month = 1, .day = 18};
    lxw_datetime datetime7 = {.year = 2016, .month = 1, .day = 19};

    worksheet_write_datetime(worksheet, 0, 0, &datetime1, date_format);
    worksheet_write_datetime(worksheet, 1, 0, &datetime2, date_format);
    worksheet_write_datetime(worksheet, 2, 0, &datetime3, date_format);
    worksheet_write_datetime(worksheet, 3, 0, &datetime4, date_format);
    worksheet_write_datetime(worksheet, 4, 0, &datetime5, date_format);
    worksheet_write_datetime(worksheet, 5, 0, &datetime6, date_format);
    worksheet_write_datetime(worksheet, 6, 0, &datetime7, date_format);

    worksheet_write_number(worksheet, 0, 1, 10, NULL);
    worksheet_write_number(worksheet, 1, 1, 20, NULL);
    worksheet_write_number(worksheet, 2, 1, 30, NULL);
    worksheet_write_number(worksheet, 3, 1, 10, NULL);
    worksheet_write_number(worksheet, 4, 1, 30, NULL);
    worksheet_write_number(worksheet, 5, 1, 10, NULL);
    worksheet_write_number(worksheet, 6, 1, 20, NULL);

    /* Create a chart object. */
    lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);

    /* Add a chart series. */
    chart_add_series(chart, "=Sheet1!$A$1:$A$7", "=Sheet1!$B$1:$B$7");

    /* Rotate the axis data text to make it easier to read. */
    lxw_chart_font font = {.rotation = -30};
    chart_axis_set_num_font(chart->x_axis, &font);

    /* Insert the chart into the worksheet. */
    worksheet_insert_chart(worksheet, CELL("D2"), chart);

    return workbook_close(workbook);
}

Output:
aa_image

@jmcnamara jmcnamara modified the milestones: Phase3, Phase5 Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants