ChartXValueCollection

ChartXValueCollection class

Represents a collection of X values for a chart series.

public class ChartXValueCollection : IEnumerable<ChartXValue>

Properties

NameDescription
Count { get; }Gets the number of items in this collection.
Item { get; set; }Gets or sets the X value at the specified index.

Methods

NameDescription
GetEnumerator()Returns an enumerator object.

Remarks

All items of the collection other than null must have the same ValueType.

The collection allows only changing X values. To add or insert new values to a chart series, or remove values, the appropriate methods of the ChartSeries class can be used.

Examples

Shows how to get chart series data.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder();

Shape shape = builder.InsertChart(ChartType.Column, 432, 252);
Chart chart = shape.Chart;
ChartSeries series = chart.Series[0];

double minValue = double.MaxValue;
int minValueIndex = 0;
double maxValue = double.MinValue;
int maxValueIndex = 0;

for (int i = 0; i < series.YValues.Count; i++)
{
    // Clear individual format of all data points.
    // Data points and data values are one-to-one in column charts.
    series.DataPoints[i].ClearFormat();

    // Get Y value.
    double yValue = series.YValues[i].DoubleValue;

    if (yValue < minValue)
    {
        minValue = yValue;
        minValueIndex = i;
    }

    if (yValue > maxValue)
    {
        maxValue = yValue;
        maxValueIndex = i;
    }
}

// Change colors of the max and min values.
series.DataPoints[minValueIndex].Format.Fill.ForeColor = Color.Red;
series.DataPoints[maxValueIndex].Format.Fill.ForeColor = Color.Green;

doc.Save(ArtifactsDir + "Charts.GetChartSeriesData.docx");

See Also