Saving charts with dynamic view

前端 未结 1 1435
孤独总比滥情好
孤独总比滥情好 2021-01-25 09:23

In my WinForms application, I have to display line graphs.

One feature which I need to implement in my application is saving the chart to a file. Once the chart is save

相关标签:
1条回答
  • 2021-01-25 09:55

    You have a couple of options:

    • Save as Jpg or Png in a size large enough to zoom in. To do so you would enlarge the chart before saving and then shrink it again.

    • Save in one of the emf formats. This saves a vector format, so zooming in works very well, even at large zoom factors. ((erroneous rant omitted))

    • Save to XML. This means serializing, either using the standard options or by marking certain properties as serializable or non-serializable. See here for more info! This code is straight from the link:

      string yourChartDataFile = "d:\\SavedChartData.xml";
      
      private void saveButton_Click(object sender, EventArgs e)
      {
          chart1.Serializer.Save(yourChartDataFile);
      }
      
      private void loadButton_Click(object sender, EventArgs e)
      {
          chart1.Serializer.Load(yourChartDataFile);
      }
      

    To display the resulting file you need another chart control, obviously.

    I found the two-liner above to work pretty well without adding frills, but you may need or want to save things like current zoom state or annotation states; I'm not sure just what does get serialized out of the box and what does not..

    Update Actually you can view and work with emf by loading them into a Metafile, which can be loaded into a PictureBox or drawn in a suitable size with Graphics.DrawImage..

    0 讨论(0)
提交回复
热议问题