Ejemplo n.º 1
0
        public static ChartData Read(string fileName)
        {
            ChartSerializer s    = new ChartSerializer();
            ChartData       data = new ChartData();

            if (System.IO.File.Exists(fileName))
            {
                using (XmlReader r = XmlReader.Create(fileName))
                {
                    s.r = r;
                    while (r.Read() && !r.EOF && r.NodeType != XmlNodeType.EndElement)
                    {
                        switch (r.NodeType)
                        {
                        case XmlNodeType.Element:
                            if (r.LocalName == "ChartData")
                            {
                                data = s.ReadChart();
                            }
                            break;
                        }
                    }
                }
            }
            return(data);
        }
Ejemplo n.º 2
0
        //=========================== Save =============================================
        public static void Write(ChartData data, string fileName)
        {
            ChartSerializer s = new ChartSerializer();

            using (XmlTextWriter w = new XmlTextWriter(fileName, Encoding.UTF8))
            {
                s.w          = w;
                w.Formatting = Formatting.Indented;
                w.WriteStartElement("ChartData");
                if (!string.IsNullOrEmpty(data.Title))
                {
                    w.WriteAttributeString("Title", data.Title);
                }
                foreach (ChartCategory c in data.Categories)
                {
                    s.WriteCategory(c);
                }
                foreach (ChartSeries series in data.AllSeries)
                {
                    s.WriteSeries(series);
                }
                w.WriteEndElement();
            }
        }