Hello Randy, thank you for the reply.
I am using ChartFX 7 with the latest service pack installed (7.0.3306.26568).
I am writing in Visual Studio 2008 for C#.
The code sample I am supplying is a bit extensive, so I will
try my best to explain as much as possible. The data source I am giving the
chart is stored in a custom linked list. Each list node is an object I made
which contains several variables. The ‘data’ variable is the most
important here, because this is where each curve’s data points are
stored, in a form of an ArrayList.
Here is a portion of my node class:
public class node
{
//
pointer references to next and previous nodes
public
node next, prev;
public
string columnName;
public
string units;
// curve data points
stored here
public
ArrayList data;
public
int maxDecimalPlace;
public
bool showCurve;
public
bool axisForceZero;
public
bool isXAxis;
public
Color curveColor;
public
DashStyle curveLineStyle;
public
MarkerShape curverMarkerShape;
public
short curveLineWidth;
/// <summary>
/// empty constructor
/// </summary>
public
node()
{
}
}
Each of my nodes contain enough information to plot a single
curve. So basically, each node IS a curve on the chart. When I need to plot
multiple curves, I store each of these curves in the linked list. I traverse
the list, from beginning to end, when I want to plot all the curves onto a
single chart. As I go through each node, I add the node’s ArrayList of
data points into an array of Objects called ‘allArrays’. After I’m
done traversing the list, I create a ListProvider with the allArrays and then
set the chart’s data source to my List Provide.
Here is my method for plotting curves:
private void
plotGraph()
{
// begin at the end of the linked list
node myNode = dataList.tail;
// clear chart data
chartWhole.Data.Clear();
// linked list node must contain data
if (myNode != null)
{
int index = 0;
// object array that stores each curve's data set
// this will be passed into a ListProvider for the
chart
object[] allArrays = new
object[dataList.numberOfVisableCurves()];
// set the number of series and data points
// performace note: manually setting the number of
series and data point values will
// improve plotting performace as dynamically
changing the number of series and points
// will impact performace significantly
chartWhole.Data.Series = dataList.numberOfVisableCurves();
chartWhole.Data.Points = myNode.data.Count;
// traverse the linked list
while (myNode != null)
{
if ((myNode.showCurve) &&
!(myNode.isXAxis))
{
// initialize chart visual attributes
chartWhole.Series[index].Color = myNode.curveColor;
chartWhole.Series[index].Line.Style = myNode.curveLineStyle;
chartWhole.Series[index].MarkerShape = myNode.curverMarkerShape;
chartWhole.Series[index].Line.Width = myNode.curveLineWidth;
chartWhole.Series[index].PointLabels.Visible = false;
// data is an ArrayList in the node that stores the curve's
data points
allArrays[index] = myNode.data;
// set the series name
chartWhole.Series[index].Text = myNode.columnName + "
" + myNode.units;
// create a new axis for each curve
AxisY AddlAxisY = new AxisY();
AddlAxisY.TextColor = chartWhole.Series[index].Color;
AddlAxisY.Visible = true;
// divide first half of axis titles on the left side
if (index < ((float)dataList.numberOfVisableCurves()
- 1) / (float)2)
{
AddlAxisY.Position = AxisPosition.Near;
}
// divide last half of axis titles on the right side
else
{
AddlAxisY.Position
= AxisPosition.Far;
}
AddlAxisY.ForceZero = myNode.axisForceZero;
AddlAxisY.LabelsFormat.Decimals = myNode.maxDecimalPlace;
chartWhole.AxesY.Add(AddlAxisY);
chartWhole.Series[index].AxisY = AddlAxisY;
index++;
}
myNode = myNode.prev;
}
// create the list provider that contains the Object
array of data points
ListProvider lstProvider = new
ListProvider(allArrays);
chartWhole.DataSourceSettings.DataSource = lstProvider;
// x-axis labels
chartWhole.AxisX.Visible
= true;
// x-axis title
chartWhole.AxisX.Title.Text = dataList.tail.columnName + " " + dataList.tail.units;
chartWhole.AxisX.ScaleUnit = dataList.tail.data.Count / 10;
chartWhole.RecalculateScale();
// the x-axis contains values in date time format
// set the x-axis labels to display date time instead
of numbers
for (int i = 0;
i < dataList.tail.data.Count; i++)
{
chartWhole.AxisX.Labels[i] = Convert.ToString(dataList.tail.data[i]);
}
}
chartWhole.RecalculateScale();
}
I use the Axis min and max values in a function that I took
out the ZoomScrollBar example from the demo’s section of the ChartFX
website. What I want to do in my project is exactly what is done in the
ZoomScrollBar example. I want to create a highlighted selection on a main
chart, and have a second chart perform a zoomed in version on the selection.
Here is the code I took and modified from the ZoomScrollBar example:
/// <summary>
/// This method creates the
AxisSection. AxisSection highlights part of the chart, given a from and a to.
/// We will use this to
indicate what part of the whole chart we are analyzing.
/// </summary>
private void
CreateAxisSection()
{
Section = new AxisSection();
chartWhole.AxisX.Sections.Add(Section);
Section.BackColor = Color.LightCyan;
Section.FontStyle = FontStyle.Bold;
// min and max values are not set properly here, always being set to 1.7976XXXXXXXXXXXXE+308
and -1.79769313486231E+308.
Section.From = chartWhole.AxisX.Min;
Section.To = chartWhole.AxisX.Min + ((chartWhole.AxisX.Max -
chartWhole.AxisX.Min) * 0.2);
ScrollSize = Section.To - Section.From;
}
Putting my code together I have, I called plotGraph() first,
to create my curves, and then I call CreateAxisSelection() right after to get
my highlighted selection in. The min and max variables of my AxisX are always
being set to 1.7976XXXXXXXXXXXXE+308 and -1.79769313486231E+308.
Just to test another thing out, in the ZoomScrollBar
example, the chart data comes from a TextProvider, instead of a ListProvider. When
I replaced the ListProvider in my PlotGraph() method with a TextProvider, the
AxisX min and max are properly set. Which leads me to think that there is a
problem when the data is presented in the form of a ListProvider.
What do you think?
Will Lo
Software Developer
Canada Tech
#7, 7875 - 48 Ave.
Red Deer, AB Canada, T4P 2K1
Office: 403-314-3659