How to change Chart's MaxAxisValue ?

Home Forums Open-Xml-Sdk How to change Chart's MaxAxisValue ?

Tagged: ,

This topic contains 3 replies, has 2 voices, and was last updated by  rogersb 8 years, 3 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #3750

    rogersb
    Participant

    I made a word doc used like a Template, at runtime load the .docx file then in code find the parts to use and modify them. Its worked well. But the chart, am trying to modify the MaxAxisValue also at runtime, but cannot “find” it in the blob.

        C2.MaxAxisValue maxAxisV = new DocumentFormat.OpenXml.Drawing.Charts.MaxAxisValue() { Val = 2 };  
            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(R.id).FirstOrDefault();
                            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)
                                cc2.ReplaceWith(newContent);
                                mainDoc.PutXDocument();
                            }
                        }
    
    

    In the parsed out Word document, here is the target:

     C.Scaling scaling2 = new C.Scaling();
                C.Orientation orientation2 = new C.Orientation(){ Val = C.OrientationValues.MinMax };
                C.MaxAxisValue maxAxisValue1 = new C.MaxAxisValue(){ Val = 1.0001D };
                C.MinAxisValue minAxisValue1 = new C.MinAxisValue(){ Val = -1.0000000000000003E-4D };
    
                scaling2.Append(orientation2);
                scaling2.Append(maxAxisValue1);
                scaling2.Append(minAxisValue1);
    

    I had to set the scaling on the word document to be .0001 instead of 0 and 1.0001 instead of 1, or it doesnt work right. but now the C.MaxAxisValue, where is it in the blob?

    #3752

    rogersb
    Participant

    in the document under /word/charts/chart1.xml <>c:chart(Chart) there is:

     <c:barChart>
    
     <c:valAx>
      <c:axId val="422883200" />
      <c:scaling>
        <c:orientation val="minMax" />
        <c:max val="1.0001" />
        <c:min val="-1.0000000000000003E-4" />
      </c:scaling>
    In the reflected code:
    
     ValueAxis valueAxis1 = new ValueAxis();
            AxisId axisId4 = new AxisId(){ Val = (UInt32Value)422883200U };
    
            Scaling scaling2 = new Scaling();
            Orientation orientation2 = new Orientation(){ Val = OrientationValues.MinMax };
            MaxAxisValue maxAxisValue1 = new MaxAxisValue(){ Val = 1.0001D };
            MinAxisValue minAxisValue1 = new MinAxisValue(){ Val = -1.0000000000000003E-4D };
    
            scaling2.Append(orientation2);
            scaling2.Append(maxAxisValue1);
            scaling2.Append(minAxisValue1);
            Delete delete2 = new Delete(){ Val = false };
            AxisPosition axisPosition2 = new AxisPosition(){ Val = AxisPositionValues.Bottom };

    how can this be found within chartPart? I have this elaborate scheme to modify a charts values, but where is scaling found and how can the maxAxisValue1 be appended?

    I dont want to have to recreate the entire logic which is currently nearly 20,000 LOC to modify the barchart

    #3762

    Eric White
    Keymaster

    Hi,

    I don’t know the specifics of the question you are asking. I have done some work with charts, in the area of setting / getting the data behind the chart, but I haven’t done any work in this area.

    Probably you know about this, but the easiest way to research Open XML markup is demonstrated in the following screen-cast:

    How to Research Open XML Markup

    In order to answer your question, I only would need to follow the procedure detailed in the above screen-cast.

    It is screen-cast #13 at the following link:

    Introduction to Open XML

    The others may be of interest too.

    Cheers, Eric

    #3776

    rogersb
    Participant

    Yes I watched this and other videos, they are very well made and helpful.

    I think a better question would be how to modify the chartPart? This was actually your code that I adapted and made work within the needs of the project, its not so much modifying the micro detail thing axis value, but how, in general, can either chartPart or chartData, be modified?

    I’ve tried the 100 monkeys chained to 100 typewriters with endless paper, cigarettes and coffee typing randomly approach to try and find any matching code that can change a parameter of chartPart to no avail.

    so I have the chartPart, ChartPart chartPart = (ChartPart)mainDoc.GetPartById(chartRid);

    can this chartPart be modified in the code, at all?

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.