I use the charting library TeeChart from Steema for one of my clients. This library is large and rambling, uses non-conventional naming schemes, and lacks good documentation. On the other hand, it does allow the user to do some very nice things with plots, if she can figure out how to do them. It wouldn't be my first choice for a plotting library, but the client has it and has asked me to use it, so use it I will.
In TeeChart, one adds to data to a chart in the form of a series. There are all sorts of useful, predefined series to choose from, but the most basic is a Line series. I add (x,y) points to the Line series, and when plotted, those points are connected with a straight line. By default, TeeChart sorts the points on the x-value, which for time series data makes sense. But for a lot of my work, I'm plotting generalized 2D paths, so it is imperative that the points maintain the ordering that I assign to them. To turn off sorting for a TeeChart Line series, use the following:
Steema.TeeChart.Styles.Line dataSeries = new Steema.TeeChart.Styles.Lines();
dataSeries.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.None;
dataSeries.YValues.Order = Steema.TeeChart.Styles.ValueListOrder.None;
If you want your points to automatically be sorted on the y-value, then use the HorizLine series.
That problem I was able to solve after searching on Google and the Steema forums. The next two problems have been trickier.
First, I want to be able to reposition an axis Title. ("Title" is the Steema terminology; to me it should be called an axis label, but they use "Label" to mean the labels associated with axis tick marks.) By default the axis title is centered on the axis. I'd like to be able to move it along the axis because if I've positioned my axis so that it is not at the edge of the plot (e.g. if I have the axis at the center of the plot), then the data that I'm plotting might sit right on top of the axis label. According to Steema, Titles cannot be repositioned, so I'm supposed to use Annotations and work out their position based on the position of the axis and the size of its tick marks. Seems like a big pain, if you ask me!
My second problem is the color that is automatically assigned to a series. TeeChart has 11 built in color palettes, and to switch between them you do the following:
Steema.TeeChart.TChart chart;
int paletteIndex;
chart.Aspect.ColorPaletteIndex = paletteIndex;
I've also seen it done this way:
Steema.TeeChart.Themes.ColorPalettes.ApplyPalette(chart, paletteIndex);
Then when series are added to the chart, each one is assigned the next color in the palette (there seems to be about 15-20 colors in each palette). But when you get to the end of the palette, every new series gets the last color in the palette. The indexer doesn't seem to wrap around back to the start of palette. To work around this, I wrote my own code to rotate through a list of colors, and I manually set the series color each time I add a new series, using code like this:
dataSeries.Color = GetColor();
static int colorIndex = 0;
private static System.Drawing.Color GetColor()
{
++colorIndex;
if (colorIndex > 3)
colorIndex = 0;
switch (colorIndex)
{
case 0:
return System.Drawing.Color.Red;
case 1:
return System.Drawing.Color.Blue;
case 2:
return System.Drawing.Color.Green;
}
return System.Drawing.Color.Black;
}
This solution is fine, but seems like it should be unnecessary!