This project has moved. For the latest updates, please go here.

Question about XYScatterSmoothNoMarkers and ColumnClustered3D charts

Feb 13, 2011 at 2:53 AM
Hello,
I would like to ask you some questions about creating chart as the following:
  1. XYScatterSmoothNoMarkers chart and in the x - axis, they will be date time value such as 2011/02/13 10:30:20 AM after it's saved I opened this xlsx file, date time value in x - axis were overlapped each other. How can I set alignment to be horizontal for text direction and -45 degree for custom angle? If it cannot be done, there are some possibility of sub-heading to show date time value for the first and last axis data?
  2. ColumnClustered3D chart, after saving excel for this chart, I found that the chart was rotated by default. I checked it in MS Excel 2007 by right click to the chart and select 3-D Rotation menu, I found that the perspective value was 15 degree and the "Right Angle Axes" checkbox in chart scale section was not checked. I tried to check this checkbox, the chart then was not rotated as that I need. How can I set these in my code?

Thank you,

chichow

Coordinator
Feb 15, 2011 at 2:42 PM

No, it's not supported in version 2.8 unless you use a template.

But you can also work directly with the ChartXml property. Like in this sample

http://epplus.codeplex.com/discussions/236723

 ...or add the new property to the library. Heres a little walkthrough how to add the RightAngleAxes (I'll add this to the FAQ later on)...

  • First we need to find the XML node we want to set, so we open an Excelworkbook, add the graph and set the property. 
  • Save the workbook, Extract it and find the xmlNode in the xl\charts\chart1.xml file.
  • The node we want is c:chart/c:chartSpace/c:view3D/c:rAngAx/@val
  • Now we need to find the appropriate class (if it exists), in this case we can use the ExcelView3D-class.
  • Lets add the property...
const string rAngAxPath = "c:rAngAx/@val";
public bool RightAngleAxes
{
    get
    {
        return GetXmlNodeBool(rAngAxPath);
    }
    set
    {
        SetXmlNodeBool(rAngAxPath, value);
    }
}

  • The ExcelView3D has the c:chart/c:chartSpace/c:view3D as topnode, so we start the XPath from there. The Get and Set methods comes from the XMLHelper base class.

Lets add two more properties, just for the sample...

  •        const string depthPercentPath = "c:depthPercent/@val";
           public int DepthPercent
           {
               get
               {
                   return GetXmlNodeInt(depthPercentPath);
               }
               set
               {
                   if (value < 0 || value > 2000)
                   {
                       throw(new ArgumentOutOfRangeException("Value must be between 0 and 2000"));
                   }
                   SetXmlNodeString(depthPercentPath, value.ToString());
               }
           }
           const string heightPercentPath = "c:hPercent/@val";
           public int HeightPercent
           {
               get
               {
                   return GetXmlNodeInt(heightPercentPath);
               }
               set
               {
                   if (value < 5 || value > 500)
                   {
                       throw (new ArgumentOutOfRangeException("Value must be between 5 and 500"));
                   }
                   SetXmlNodeString(heightPercentPath, value.ToString());
               }
           }
    
    
  • One thing left to do. Its important the the xml-elements comes in the correct order according to the schema, so we must ensure that. As help we use the SchemaNodeOrder property to ensure the elements are created at the correct place...
  • public ExcelView3D(XmlNamespaceManager ns, XmlNode node)
               : base(ns,node)
    {
               //SchemaNodeOrder = new string[] { "rotX", "rotY", "perspective" };
               SchemaNodeOrder = new string[] { "rotX", "hPercent", "rotY", "depthPercent", "perspective", "rAngAx"};
    }
    
    
  • So we change the property in the constructor. And we are done.

I'll add this to the library next time i check in.
Jan