Horiz Bar chart with 3 values does not scale right RRS feed

  • Question

  • Im using a word document as a template with OpenXML.  I created a horiz bar chart to display 3 values and then modify their values at runtime

     var mdXDoc = mainDoc.GetXDocument();
                        var cc2 = mdXDoc.Descendants(W.sdt)
            .FirstOrDefault(sdt => (string)sdt.Elements(W.sdtPr).Elements(W.tag).Attributes(W.val).First() == "Chart1");
                        if (cc2 != null)
                            var chartRid = "rId5";// (string)cc.Descendants(C.chart).Attributes(;
                            if (chartRid != null)
                                ChartPart chartPart = (ChartPart)mainDoc.GetPartById(chartRid);
                                UpdateChart(chartPart, chartData);
                                var newContent = cc2.Elements(W.sdtContent).Elements().Select(e => new XElement(e));
                                // cc.AddAfterSelf(newContent)

    it worked fine when I kept the values at 0 to 100 (%)  the scaling was right for all 3 columns.  But some of the data goes over 100%

    On the Chart, I dont know which of the 3 it scales to. Seems to be the first one. value is 80 and it lands on the 80 mark on the scale at the bottom. 

    the top column is 102 ?  and its just shorter than 100.  Another was 207? and its going from 0 to about 65%  so its scaling the 207 based on something.    102 draws the bar just less than 100?  so it looks odd but 207 is much less, its not set to logarithmic

    there just needs to be some way to indicate the value went over 100.  The bars are a nice green color, if the column color could be changed and add some icon like "!"

    In the document itself I have the horizontal scale locked in between .0001 and .9999 so that it will not auto-scale because it causes a different problem, if the chart is set to auto scale, then if the column values are say 89, 90 and 100?  it will shift them to be more or less centered and instead of 0 - 100 on the horiz scale marks at the bottom, they are set to something like:  83 - 100.  

    Absolute requirement the scale at the bottom starts at 0, but when the other values are over 100 ??  how are all 3 scaled to the largest one?  

    Monday, August 15, 2016 8:42 PM


  • Hi,

    How do you create the bar chart, manually and dynamically? And what specific kinds of barchart do you create? Do you try to replace the content manually after you create the chart and if it would cause the issue?


    Since you are using OpenXML to change the chart content, I suggest you use OpenXML SDK Tool,  which could reflect code by comparing files.

    You could download Open XML SDK Tool from

    You could follow the steps below:

    1. Create two documents with one is original file and one is the target file;

    2. Use Open XML SDK 2.5 productivity Tool for Microsoft Office

    3. Click the Compare Files, generate the code, and then you could get the code what you want

    Wednesday, August 17, 2016 5:46 AM