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

Adding font to Chart data_labels cause error #179

Closed
georgelovas opened this Issue Nov 11, 2014 · 14 comments

Comments

2 participants
@georgelovas

georgelovas commented Nov 11, 2014

Adding any font attribute to chart data_labels causes the following error on write:

File "C:\Python34\lib\site-packages\xlsxwriter\chart.py", line 1184, in _get_font_style_attributes
attributes.append(('baseline', font['baseline']))
KeyError: 'baseline'

Using XlsxWriter version 0.6.3 (also failed on earlier versions) with python 3.4

sample code below:

chart1.add_series({
    'name':       ['Sheet1', 0, 2],
    'categories': ['Sheet1', 1, 0, 6, 0],
    'values':     ['Sheet1', 1, 2, 6, 2],
    'data_labels': {
        'value': True,
        'font': {'name': 'Consolas'}
    },
})

thanks
George Lovas

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 11, 2014

Owner

Hi George,

Thanks, that is a bug. I post a fix in the next day or two. In the meantime you can workaround it if you like using something like the following:

chart.add_series({
    'categories': '=Sheet1!$A$2:$A$7',
    'values':     '=Sheet1!$B$2:$B$7',
    'data_labels': {
        'value': True,
        'font': {'name': 'Consolas', 
                 'baseline': -1, 
                 'pitch_family': 49,  
                 'charset': 0}
    },
})

Regards,

John

Owner

jmcnamara commented Nov 11, 2014

Hi George,

Thanks, that is a bug. I post a fix in the next day or two. In the meantime you can workaround it if you like using something like the following:

chart.add_series({
    'categories': '=Sheet1!$A$2:$A$7',
    'values':     '=Sheet1!$B$2:$B$7',
    'data_labels': {
        'value': True,
        'font': {'name': 'Consolas', 
                 'baseline': -1, 
                 'pitch_family': 49,  
                 'charset': 0}
    },
})

Regards,

John

@jmcnamara jmcnamara self-assigned this Nov 11, 2014

@jmcnamara jmcnamara added the bug label Nov 11, 2014

@jmcnamara jmcnamara changed the title from adding font to Chart data_labels cause error on write... to adding font to Chart data_labels cause error Nov 11, 2014

@jmcnamara jmcnamara changed the title from adding font to Chart data_labels cause error to Adding font to Chart data_labels cause error Nov 11, 2014

@georgelovas

This comment has been minimized.

Show comment
Hide comment
@georgelovas

georgelovas Nov 11, 2014

Hi John,

Thanks for fixing and the work around.

Best,
George

George Lovas
Quantum Solutions Plus, LLC
917-573-3079 office
917-589-5659 mobile
203-594-1999 fax

On Tue, Nov 11, 2014 at 9:56 AM, John McNamara notifications@github.com
wrote:

Hi George,

Thanks, that is a bug. I post a fix in the next day or two. In the
meantime you can workaround it if you like using something like the
following:

chart.add_series({
'categories': '=Sheet1!$A$2:$A$7',
'values': '=Sheet1!$B$2:$B$7',
'data_labels': {
'value': True,
'font': {'name': 'Consolas',
'baseline': -1,
'pitch_family': 49,
'charset': 0}
},
})

Regards,

John


Reply to this email directly or view it on GitHub
#179 (comment)
.

georgelovas commented Nov 11, 2014

Hi John,

Thanks for fixing and the work around.

Best,
George

George Lovas
Quantum Solutions Plus, LLC
917-573-3079 office
917-589-5659 mobile
203-594-1999 fax

On Tue, Nov 11, 2014 at 9:56 AM, John McNamara notifications@github.com
wrote:

Hi George,

Thanks, that is a bug. I post a fix in the next day or two. In the
meantime you can workaround it if you like using something like the
following:

chart.add_series({
'categories': '=Sheet1!$A$2:$A$7',
'values': '=Sheet1!$B$2:$B$7',
'data_labels': {
'value': True,
'font': {'name': 'Consolas',
'baseline': -1,
'pitch_family': 49,
'charset': 0}
},
})

Regards,

John


Reply to this email directly or view it on GitHub
#179 (comment)
.

@georgelovas

This comment has been minimized.

Show comment
Hide comment
@georgelovas

georgelovas Nov 11, 2014

Hi John,

Just one note regarding the workaround .. if "size" is included with the
font, it executes without error, but none of the charts appear int the
output.

Thanks,
George

georgelovas commented Nov 11, 2014

Hi John,

Just one note regarding the workaround .. if "size" is included with the
font, it executes without error, but none of the charts appear int the
output.

Thanks,
George

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 11, 2014

Owner

Hi George,

That is part of the same issue. I'll look into it.

John

Owner

jmcnamara commented Nov 11, 2014

Hi George,

That is part of the same issue. I'll look into it.

John

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 11, 2014

Owner

A workaround for the size issue, for now, is to multiple the desired size by 100.

I'll put in a proper fix however.

Owner

jmcnamara commented Nov 11, 2014

A workaround for the size issue, for now, is to multiple the desired size by 100.

I'll put in a proper fix however.

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 11, 2014

Owner

Here is a real fix that doesn't require workarounds. Apply the following diff:

$ git diff
diff --git a/xlsxwriter/chart.py b/xlsxwriter/chart.py
index dd090f3..a85b840 100644
--- a/xlsxwriter/chart.py
+++ b/xlsxwriter/chart.py
@@ -1009,6 +1009,8 @@ class Chart(xmlwriter.XMLwriter):
         if not labels:
             return None

+        labels['font'] = self._convert_font_args(labels.get('font'))
+
         # Map user defined label positions to Excel positions.
         position = labels.get('position')

I'll push a proper fix later when I can add some test cases.

Owner

jmcnamara commented Nov 11, 2014

Here is a real fix that doesn't require workarounds. Apply the following diff:

$ git diff
diff --git a/xlsxwriter/chart.py b/xlsxwriter/chart.py
index dd090f3..a85b840 100644
--- a/xlsxwriter/chart.py
+++ b/xlsxwriter/chart.py
@@ -1009,6 +1009,8 @@ class Chart(xmlwriter.XMLwriter):
         if not labels:
             return None

+        labels['font'] = self._convert_font_args(labels.get('font'))
+
         # Map user defined label positions to Excel positions.
         position = labels.get('position')

I'll push a proper fix later when I can add some test cases.

jmcnamara added a commit that referenced this issue Nov 11, 2014

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 11, 2014

Owner

Hi,

I've push a fix for this issue to master.

John

Owner

jmcnamara commented Nov 11, 2014

Hi,

I've push a fix for this issue to master.

John

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Nov 15, 2014

Owner

Fixed in release 0.6.4.

Thanks for the report.

John

Owner

jmcnamara commented Nov 15, 2014

Fixed in release 0.6.4.

Thanks for the report.

John

@jmcnamara jmcnamara closed this Nov 15, 2014

@georgelovas

This comment has been minimized.

Show comment
Hide comment
@georgelovas

georgelovas Nov 16, 2014

Hi John,

Thanks for fixing this so quickly.

Have a good rest of the weekend.

Best,
George

georgelovas commented Nov 16, 2014

Hi John,

Thanks for fixing this so quickly.

Have a good rest of the weekend.

Best,
George

@georgelovas

This comment has been minimized.

Show comment
Hide comment
@georgelovas

georgelovas Dec 29, 2014

Hi John,

Hope you had a good Christmas...

Quick question? Is it possible to add data label for the last point in a
series like the attached example?

Thanks,
George

georgelovas commented Dec 29, 2014

Hi John,

Hope you had a good Christmas...

Quick question? Is it possible to add data label for the last point in a
series like the attached example?

Thanks,
George

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Dec 29, 2014

Owner

Hi George,

There wasn't an attachment since GitHub doesn't allow them.

However, I take it that you mean adding a label to just 1 point, or the start end end points.

That isn't possible in XlsxWriter since there is very little control over individual points apart from their colour.

If you like you can add a feature request but it is a fairly uncommon request so it unlikely to gain enough +1 votes to get moved up the TODO list.

Regards,

John

Owner

jmcnamara commented Dec 29, 2014

Hi George,

There wasn't an attachment since GitHub doesn't allow them.

However, I take it that you mean adding a label to just 1 point, or the start end end points.

That isn't possible in XlsxWriter since there is very little control over individual points apart from their colour.

If you like you can add a feature request but it is a fairly uncommon request so it unlikely to gain enough +1 votes to get moved up the TODO list.

Regards,

John

@georgelovas

This comment has been minimized.

Show comment
Hide comment
@georgelovas

georgelovas Dec 29, 2014

Hi John,

Yes, its adding a data label to the last point... Image included at end if
github allows...

I looked at chart.xml in the unzipped xlsx file and the change seems fairly
innocuous: Adding a data label to the last point just requires adding a
<c.dLbl> element with the point index to <c.dLbls>. In my example below,
there are 60 points.

Is there more to it than this?

Thanks,
George

No Data Labels
-<c:dLbls>

<c:showLegendKey val="0"/>
<c:showVal val="0"/>
<c:showCatName val="0"/>
<c:showSerName val="0"/>
<c:showPercent val="0"/>
<c:showBubbleSize val="0"/>

/c:dLbls

Every Point Data Labels
-<c:dLbls>

<c:showLegendKey val="0"/>
<c:showVal val="1"/>
<c:showCatName val="0"/>
<c:showSerName val="0"/>
<c:showPercent val="0"/>
<c:showBubbleSize val="0"/>
<c:showLeaderLines val="0"/>

/c:dLbls

Last Point Only
-<c:dLbls>

-<c:dLbl>

<c:idx val="60"/>

<c:layout/>

<c:showLegendKey val="0"/>

<c:showVal val="1"/>

<c:showCatName val="0"/>

<c:showSerName val="0"/>

<c:showPercent val="0"/>

<c:showBubbleSize val="0"/>

/c:dLbl
<c:showLegendKey val="0"/>
<c:showVal val="0"/>
<c:showCatName val="0"/>
<c:showSerName val="0"/>
<c:showPercent val="0"/>
<c:showBubbleSize val="0"/>

/c:dLbls

[image: Inline image 2]

George Lovas

georgelovas commented Dec 29, 2014

Hi John,

Yes, its adding a data label to the last point... Image included at end if
github allows...

I looked at chart.xml in the unzipped xlsx file and the change seems fairly
innocuous: Adding a data label to the last point just requires adding a
<c.dLbl> element with the point index to <c.dLbls>. In my example below,
there are 60 points.

Is there more to it than this?

Thanks,
George

No Data Labels
-<c:dLbls>

<c:showLegendKey val="0"/>
<c:showVal val="0"/>
<c:showCatName val="0"/>
<c:showSerName val="0"/>
<c:showPercent val="0"/>
<c:showBubbleSize val="0"/>

/c:dLbls

Every Point Data Labels
-<c:dLbls>

<c:showLegendKey val="0"/>
<c:showVal val="1"/>
<c:showCatName val="0"/>
<c:showSerName val="0"/>
<c:showPercent val="0"/>
<c:showBubbleSize val="0"/>
<c:showLeaderLines val="0"/>

/c:dLbls

Last Point Only
-<c:dLbls>

-<c:dLbl>

<c:idx val="60"/>

<c:layout/>

<c:showLegendKey val="0"/>

<c:showVal val="1"/>

<c:showCatName val="0"/>

<c:showSerName val="0"/>

<c:showPercent val="0"/>

<c:showBubbleSize val="0"/>

/c:dLbl
<c:showLegendKey val="0"/>
<c:showVal val="0"/>
<c:showCatName val="0"/>
<c:showSerName val="0"/>
<c:showPercent val="0"/>
<c:showBubbleSize val="0"/>

/c:dLbls

[image: Inline image 2]

George Lovas

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Dec 29, 2014

Owner

Is there more to it than this?

Time. Tests. Documentation.

There are at least 15 items on the current TODO list and new features get low priority until they get more than a few requests.

John

Owner

jmcnamara commented Dec 29, 2014

Is there more to it than this?

Time. Tests. Documentation.

There are at least 15 items on the current TODO list and new features get low priority until they get more than a few requests.

John

@georgelovas

This comment has been minimized.

Show comment
Hide comment
@georgelovas

georgelovas Dec 29, 2014

Hi John,

Yes, understood. I'll add to the feature requests and see if others are
interested.

Thanks and Happy New Year.
George

georgelovas commented Dec 29, 2014

Hi John,

Yes, understood. I'll add to the feature requests and see if others are
interested.

Thanks and Happy New Year.
George

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment