none
How to find and modify just this item in Office Doc chart? RRS feed

  • Question

  •  <c:chart>
     
     
      <c:plotArea>
       <c:layout/>
     
    
       <c:valAx>
        <c:axId val="470561776"/>
        <c:scaling>
         <c:orientation val="minMax"/>
         <c:max val="1"/>
    Trying to drill into the xml and modify the value for Max axis


    Bradley :)

    Tuesday, October 11, 2016 9:48 PM

All replies

  • Hi Bradley Rogers,

    According to your description, I suggest that you could create one Word document, then insert BarChart and save. After that you could open and change the scale of the horizontal (value) axis in a chart in this document, then save as this document with an other name, refer to below link:

    Change the scale of the horizontal (category) axis in a chart

    You could compare these two document file by use Open XML SDK productivity Tool, then "View Part Code", you would get C# code to find and modify this item.

    public  void ChangeChartPart(ChartPart chartPart1)
    {
                C.ChartSpace chartSpace1 = chartPart1.ChartSpace;
    
                C.Chart chart1=chartSpace1.GetFirstChild<C.Chart>();
    
                C.PlotArea plotArea1=chart1.GetFirstChild<C.PlotArea>();
    
                C.ValueAxis valueAxis1=plotArea1.GetFirstChild<C.ValueAxis>();
    
                C.Scaling scaling1=valueAxis1.GetFirstChild<C.Scaling>();
    
                C.MinAxisValue minAxisValue1 = new C.MinAxisValue(){ Val = 3D };
                scaling1.Append(minAxisValue1);
    }


    Thanks for your understanding.


    • Edited by David_JunFeng Wednesday, October 12, 2016 2:04 AM
    • Proposed as answer by David_JunFeng Thursday, October 20, 2016 1:23 AM
    Wednesday, October 12, 2016 2:04 AM
  • Hi David

    yes, that is how I found the item I needed to change.  I hope to be able to modify this, but one problem, the chart is inside a content control.  I dont know how to "find" the chart any other way.

    It will be one chart on one form that never changes.  my form is used like a template with pre existing areas and content controls.

    Ive found that once I modify the chart part?  thats it, you can only modify it once.  then it gets locked out and any further code has no effect on it.  I would have one part like your example to modify the axis, the other part to modify the values.

    In the application, the bar chart MUST scale for values over 100%, which it does.  But what I do is use a stacked bar chart, so a colored version for the value and grey to show the remainder to 100.  When the scale goes to 120 the lower values still show up with the grey part there that stops at 100.  It is the design requirement to do this.

    but what the barchart does is when the stacked values are there adding to 100?  the scale decides it wants to extend out to 120.  no command in the universe exists to stop this.  that I can find.

    If you switch the type to barchart 0-100% then it stops at 100.  period.  if your value is 125? the axis will never extend, its 100 always.  so 125 has the bar shrink a bit so it looks like maybe 90%, its non linear.  250% looks like maybe 60

    the only hope is to override the setting for the max axis based on calculated values and hope the bars line up right

    looks like your good example modifies min axis, but its ok, I have not tried this method yet, will apply it now, thank you


    Bradley :)

    Wednesday, October 12, 2016 2:57 AM
  • >>>I hope to be able to modify this, but one problem, the chart is inside a content control.  I dont know how to "find" the chart any other way.

    According to your description, I suggest that you could refer to previous reply to compare two document file to get reflect C# code by using Open XML SDK Productivity Tool.

    >>>If you switch the type to barchart 0-100% then it stops at 100.  period.  if your value is 125? the axis will never extend, its 100 always.  so 125 has the bar shrink a bit so it looks like maybe 90%, its non linear.  250% looks like maybe 60

    Could you manually change this barchart? If you are not able to do it, it is impossible to use Open XML SDK.

    Thanks for your understanding.

    Friday, October 14, 2016 8:41 AM