jmcnamara / XlsxWriter

A Python module for creating Excel XLSX files.
https://xlsxwriter.readthedocs.io
BSD 2-Clause "Simplified" License
3.66k stars 631 forks source link

Chart: in a discontinuous series, the data label isn't displayed #1069

Closed youth54 closed 6 months ago

youth54 commented 6 months ago

Question

hello, I have read the chart-series-option-data-labels document

try to add data label in a discontinuous series, but it's not work.

thanks a lot

example as follow version: 3.2.0

import xlsxwriter
print(xlsxwriter.__version__)

workbook = xlsxwriter.Workbook("chart.xlsx")
worksheet = workbook.add_worksheet()

# Create a new Chart object.
chart = workbook.add_chart({"type": "column"})

# Write some data to add to plot on the chart.
index = ["A", "B", "C", "D", "E", "F", "G"]
data = [1, 2, 3, 4, 5, 6, 7]

worksheet.write_column("A1", index)
worksheet.write_column("B1", data)

worksheet.write_string("D1", "tag1")
worksheet.write_string("D2", "tag2")

# Configure the charts. In simplest case we just add some data series.
tag1_labels = [
    {'delete': True},
    {'delete': True},
    {"value": "=Sheet1!$D$1"},  # tag1
    {'delete': True},
    {'delete': True},
    {'delete': True},
    {'delete': True},
]

tag2_labels = [
    {'delete': True},
    {'delete': True},
    {'delete': True},
    {'delete': True},
    {'delete': True},
    {"value": "=Sheet1!$D$2"},  # tag2
    {'delete': True},
]
chart.add_series({
    "name": "First",
    "categories": "=Sheet1!$A$1:$A$7",
    "values": "=(Sheet1!$B$1:$B$4,Sheet1!$C$1:$C$3)",  # non-contiguous ranges
    "data_labels": {
        "value": True,
        "custom": tag1_labels
    }
})

chart.add_series({
    "name": "Second",
    "categories": "=Sheet1!$A$1:$A$7",
    "values": "=(Sheet1!$C$1:$C$4,Sheet1!$B$5:$B$7)", # non-contiguous ranges 
    "data_labels": {
        "value": True,
        "custom": tag2_labels
    }
})

# Insert the chart into the worksheet.
worksheet.insert_chart("A10", chart)

workbook.close()
jmcnamara commented 6 months ago

It seems to work okay. Here is the output from your sample program:

screenshot 8

What is the issue you are seeing?

youth54 commented 6 months ago

I open it useing WPS Office software. I don't see the tag labels.

maybe, in this case, WPS isn't compalite with MS office.

thanks again, i will find another method.

jmcnamara commented 6 months ago

Ok. In that case I will close it.