locked
How can I only serialize data points ? RRS feed

  • Question

  •  The Part A is a full serialized data, but I hope to get only Part B, how can I do? thanks!

    The following code don't work!

       protected void Button1_Click(object sender, EventArgs e)
        {
            Chart1.Serializer.SerializableContent = "*.DataPoint";
            this.Chart1.Serializer.Save(@"c:\1.xml");
        }

    ------------------------------Part A----------------------
     <Chart>
     <Series>
     <Series Name="Series1" ChartArea="ChartArea1">
     <Points>
      <DataPoint XValue="3" YValues="1,2" />
      <DataPoint XValue="7" YValues="5,10" />
      <DataPoint XValue="6" YValues="7,14" />
      </Points>
      </Series>
      </Series>
     <ChartAreas>
      <ChartArea Name="ChartArea1" /> 
    </ChartAreas>
    </Chart>
    ------------------------------Part A----------------------


    ------------------------------Part B----------------------
     <Points>
      <DataPoint XValue="3" YValues="1,2" />
      <DataPoint XValue="7" YValues="5,10" />
      <DataPoint XValue="6" YValues="7,14" /> 
    </Points>
    ------------------------------Part B----------------------


    Free online bookmark manager http://www.hellocw.com/onlinebookmark/
    • Edited by CUI WEI Wednesday, January 28, 2009 1:02 PM
    Wednesday, January 28, 2009 9:32 AM

Answers

  • You can configure chart serializer to save only DataPoint collection using SerializableContent property. It will not produce exactly what you want because it will still include all the parent elements of the data points like Series and Chart itself. Pretty much you will be able to achieve option A without ChartAreas in it...

    Chart1.Serializer.SerializableContent = "Chart.Series,Series.DataPoints,DataPoint.*";

    If you can simply serialize X and Y values of the data points you can easily do it yourself as suggested in the posts above.

    Alex


    http://blogs.msdn.com/alexgor
    Thursday, January 29, 2009 4:16 PM
  • Only first one should do what you need. 2 and 3 do not serialize Chart.Series collection. When checking if property should be serialized we only check the property itself and we do not look-up their children. In other words, if you do not specify Chart.Series, then everything in that collection will not be serialized.

    Alex.
    http://blogs.msdn.com/alexgor
    Tuesday, February 3, 2009 5:22 PM

All replies

  • If you really need to use that particular XML format then I think you will need to handle serialisation/deserialisation yourself using the normal framework methods.

     

    Wednesday, January 28, 2009 10:51 AM
  • But the following don't return result I want!

     Chart1.Serializer.SerializableContent = "*.DataPoint";
      this.Chart1.Serializer.Save(@"c:\1.xml");


    Free online bookmark manager http://www.hellocw.com/onlinebookmark/
    Wednesday, January 28, 2009 10:54 AM
  • > But the following don't return result I want!

     I know. That's why I said you should use normal framework methods, i.e not the ones on the chart control. Like the XmlSerializer class, for example.

     

    Thursday, January 29, 2009 3:57 PM
  • You can configure chart serializer to save only DataPoint collection using SerializableContent property. It will not produce exactly what you want because it will still include all the parent elements of the data points like Series and Chart itself. Pretty much you will be able to achieve option A without ChartAreas in it...

    Chart1.Serializer.SerializableContent = "Chart.Series,Series.DataPoints,DataPoint.*";

    If you can simply serialize X and Y values of the data points you can easily do it yourself as suggested in the posts above.

    Alex


    http://blogs.msdn.com/alexgor
    Thursday, January 29, 2009 4:16 PM
  • Thank you very much!

    1. Maybe it should be Chart1.Serializer.SerializableContent = "Chart.Series,Series.Points,DataPoint.*"; right?

    The following is from Help document , I think it's not very clear, I don't know how to fill in SerializableContent , now I have a little understand, I must fill in root element first.

    Property Value

    A comma-separated string expression that represents the chart properties to be serialized. The syntax is "Class.Property[,Class.Property]".

     

    2.  I do more test, but the following code only get a blank XML file ( <Chart /> ) , I don't know why?

    Chart1.Serializer.SerializableContent = "*.Points,DataPoint.*";
    Or
    Chart1.Serializer.SerializableContent = "*.Points";

     

    3. And more , If I use the following code, it works well , all point data is not included in XML file,  I don't know why?

    Chart1.Serializer.NonSerializableContent = "*.Points";

     

     


    Free online bookmark manager http://www.hellocw.com/onlinebookmark/

    Friday, January 30, 2009 2:49 AM
  •  I can't reproduce this issue. After setting Serializablecontent to "Chart.Series,Series.Points,DataPoint.*" I got all the data points I expect:

     <Chart> 
     <Series> 
     <Series> 
     <Points> 
      <DataPoint YValues="100" ToolTip="100" AxisLabel="Nm1" />   
      <DataPoint YValues="250" ToolTip="250" AxisLabel="Nm2" />   
      <DataPoint YValues="300" ToolTip="300" AxisLabel="Nm3" />   
      <DataPoint YValues="500" ToolTip="500" AxisLabel="Name4" />   
      <DataPoint YValues="0" IsEmpty="True" ToolTip="278" AxisLabel="nm5" />   
      <DataPoint YValues="600" ToolTip="600" AxisLabel="NM6" />   
      <DataPoint YValues="380" ToolTip="380" AxisLabel="nm7" />   
      <DataPoint YValues="564" ToolTip="564" AxisLabel="nm8" />   
      <DataPoint YValues="567" ToolTip="567" AxisLabel="nm9" />   
      <DataPoint YValues="342" ToolTip="342" AxisLabel="nm10" />   
      <DataPoint YValues="123" ToolTip="123" AxisLabel="nm11" />   
      <DataPoint YValues="756" ToolTip="756" AxisLabel="nm12" />   
      <DataPoint YValues="908" ToolTip="908" AxisLabel="nm13" />   
      <DataPoint YValues="349" ToolTip="349" AxisLabel="nm14" />   
      <DataPoint YValues="564" ToolTip="564" AxisLabel="nm16" />   
      <DataPoint YValues="896" ToolTip="896" AxisLabel="nm15" />   
      <DataPoint YValues="453" ToolTip="453" AxisLabel="nm17" />   
      <DataPoint YValues="900" ToolTip="900" AxisLabel="nm18" />   
      <DataPoint YValues="565" ToolTip="565" AxisLabel="nm19" />   
      <DataPoint YValues="456" ToolTip="456" AxisLabel="nm20" />   
      </Points> 
      </Series> 
      </Series> 
      </Chart> 

    http://blogs.msdn.com/alexgor
    Tuesday, February 3, 2009 1:28 AM
  • 1. Chart1.Serializer.SerializableContent = "Chart.Series,Series.Points,DataPoint.*";    OK
    2. Chart1.Serializer.SerializableContent = "*.Points,DataPoint.*";                                 Fail
    3. Chart1.Serializer.SerializableContent = "*.Points";                                                    Fail
    4. Chart1.Serializer.NonSerializableContent = "*.Points";                                            OK

    I think the 1, 2 and 3 should be the same results, but the 2 and 3 only get a blank XML, I don't know why!
    Free online bookmark manager http://www.hellocw.com/onlinebookmark/
    Tuesday, February 3, 2009 10:52 AM
  • Only first one should do what you need. 2 and 3 do not serialize Chart.Series collection. When checking if property should be serialized we only check the property itself and we do not look-up their children. In other words, if you do not specify Chart.Series, then everything in that collection will not be serialized.

    Alex.
    http://blogs.msdn.com/alexgor
    Tuesday, February 3, 2009 5:22 PM
  • Hello,

    I would like to do the same thing, but only for annotations.  Is this possible?

    I tried:

    Chart.Serializer.SerializableContent = "Chart.Annotations";

    which does save to my memorystream, but then when trying to load the annotations later, nothing gets loaded when I pass in the same stream that was generated by the save method.

     

    Thursday, June 2, 2011 4:26 AM