OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
670 stars 96 forks source link

Excel chart line weight throws exception when using non-integer values #1533

Open alexuaua opened 3 years ago

alexuaua commented 3 years ago

While working on porting VSTO solution to Office JS solution, I've found that it is not possible to set line weight for chart series to a non-integer values. Documentation just says it has to be a number and one can set a line weight to any positive value using Excel UI, XLSX file format, as well as VSTO or VBA APIs. This issue also results in inability to preserve a line weight value when it's being read and write using API: default line weight is 2.25pt, but when one reads it - the API returns "2.0" and if we use value we just read to set up line weight - it changes the weight to 2.0.

Expected Behavior

Allow to set a fractional value for line weight and return actual line weight instead of rounded value. Or make a note in documentation that JS API limits weight to an integer value and the value returned is rounded to integer.

JS documentation page: https://docs.microsoft.com/en-us/javascript/api/excel/excel.chartlineformat?view=excel-js-preview#weight

VSTO page (just for comparison, because it's not retired and provides more details). https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel.lineformat.weight?view=excel-pia#Microsoft_Office_Interop_Excel_LineFormat_Weight

Current Behavior

Exception when trying to set a series line weight to default value or any other non-integer value. On read, returned value is rounded (in a hard way - floor instead of rounding) and does not reflect actual line weight - line weight 0.9pt returned as 0pt.

Steps to Reproduce, or Live Example

1) Create a chart with line or a scatter with lines. 2) Read series line weight: var series: Excel.ChartSeries = context.workbook.worksheets.getActiveWorksheet().charts.getItemAt(0).series.getItemAt(0); series.format.line.load('weight'); await ctx.sync(); var weight:number = series.format.line.weight; console.log(weight); 3) Try to set it back: series.format.line.weight = weight; await ctx.sync();

Context

1) Line weight is very useful to visually distinguish subject of interest and additional indexes (like actual value vs estimates). 2) For charts with lines with many data points it useful to adjust the line weight. 3) Inability to adjust line like with older APIs or UI makes line weight property much less usable - instead of granular control (0.25pt step or even 0.5pt step) we have only 1pt (thin line), 2pt (more thin than default),3pt (thick). I.e. there is even no option to reset line weight to default value (2.25pt). Also line weight is truncated instead of rounding and thus line with weight less than 1.0 is returned as zero.

Screen Shot 2020-12-03 at 04 32 38

Your Environment

Useful logs

lindalu-MSFT commented 3 years ago

@MandytMSFT HI, can you have a look at this one? It seems this issue has been overlooked. @alexuaua are you still experiencing this issue? So sorry for the delay. :octocat:

alexuaua commented 3 years ago

@lindalu-MSFT Thanks for keeping in touch, and yes, we do, but fortunately this issue isn't as critical as charting issues on iPad (and many users say they would really love to have charts in add-in on iPad). So far, we just added hack to round line width and round any weight < 1 upward, kind of: weight = weight < 1 /* weight is always > 0 for visible lines in our code */ ? 1 : Math.round(weight)

MandytMSFT commented 3 years ago

@lindalu-MSFT I forgot to update the thread :(. @alexuaua Thanks for reaching us, This is a real issue and we have opened Bug 4704601 for internal track but unfortunately we have no timelines to share at this point.

bestdani commented 11 months ago

I bumped into this issue as a client requested a line weight with float values to match the corporate chart design requirements. Is there any known workaround or any further activity on solving this issue?