How to change Chart's MaxAxisValue ?
Home › Forums › Open-Xml-Sdk › How to change Chart's MaxAxisValue ?
This topic contains 3 replies, has 2 voices, and was last updated by rogersb 8 years, 3 months ago.
-
AuthorPosts
-
September 8, 2016 at 7:08 pm #3750
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?
September 9, 2016 at 2:41 am #3752in 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
September 12, 2016 at 5:35 am #3762Hi,
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:
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:
The others may be of interest too.
Cheers, Eric
September 12, 2016 at 2:01 pm #3776Yes 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?
-
AuthorPosts
You must be logged in to reply to this topic.