0

I am working on an application that graphs time-based data stored in a file. Each file can have up to 5 data sets that can be graphed. The application itself can render up to 10 of these files (so it's possible for 50 graphs to be rendered on screen).

Since there could possibly be several graphs on screen-- they are line graphs, by the way-- I am looking to provide a way for users to select the color of each of the 50 possible line graphs.

I already have the user interface that will provide a simple way for users to do that. The problem is that I can't come up with an elegant way to store the color information for each of the 50 possible line graphs (persistent storage, by the way).

What I've tried so far is storing each of the 50 line color choices in an application settings file (e.g., the Properties.Settings.Default namespace). Unfortunately, there are 50 settings and they're all named sequentially, e.g. File1DataSet1Color, File1DataSet2Color, File1DataSet3Color, File1DataSet4Color, File1DataSet5Color, File2DataSet1Color, and so on. This, unfortunately, makes for some exceptionally long and repetitive graph rendering code.

So my question is this: what is an elegant solution for persistent storage of color settings for 50 line graphs, which doesn't result in brittle or repetitive code in my rendering code?

kevin628
  • 3,458
  • 3
  • 30
  • 44

2 Answers2

0

Perhaps you can serialize an array of ints to a file. (two dimensional. for the 3 parts of the color.)

BinaryFormatter formater = new BinaryFormatter();
string path = "path";
object data = "data";
using (Stream stream = File.Create(path))
    formater.Serialize(stream, data); 

Or: How to store int[] array in application Settings

Community
  • 1
  • 1
ispiro
  • 26,556
  • 38
  • 136
  • 291
  • I had wanted to avoid creating my own persistence file because that involves a lot of extra coding just to get a relatively small part of the program to function. That said, we decided to go with XML serialization, since it's already being used by older parts of the program. Not sure why I just didn't do that in the first place. Thanks for the suggestion, though! :D – kevin628 Jul 25 '12 at 16:50
0

Looks like XML serialization is the path I'll take.

kevin628
  • 3,458
  • 3
  • 30
  • 44