/// <summary> /// Creates a legend item. /// </summary> /// <returns>A legend item for insertion in the legend items collection. /// </returns> protected virtual LegendItem CreateLegendItem() { LegendItem legendItem = new LegendItem(); if (this.LegendItemStyle != null) { legendItem.Style = LegendItemStyle; } return(legendItem); }
/// <summary> /// Updates the indexes of all legend items when a change is made to the collection. /// </summary> private void UpdateLegendItemIndexes() { int index = 0; foreach (DataPoint dataPoint in ActiveDataPoints) { LegendItem legendItem = _dataPointLegendItems[dataPoint]; legendItem.Content = dataPoint.IndependentValue ?? (index + 1); index++; } }
/// <summary> /// Removes data point's legend item when the data point is removed. /// </summary> /// <param name="dataPoint">The data point to remove.</param> protected override void RemoveDataPoint(DataPoint dataPoint) { base.RemoveDataPoint(dataPoint); if (dataPoint != null) { LegendItem legendItem = _dataPointLegendItems[dataPoint]; _dataPointLegendItems.Remove(dataPoint); LegendItems.Remove(legendItem); UpdateLegendItemIndexes(); } }
/// <summary> /// Creates a legend item from a data point. /// </summary> /// <param name="dataPoint">The data point to use to create the legend item.</param> /// <param name="index">The 1-based index of the Control.</param> /// <returns>The series host legend item.</returns> private LegendItem CreatePieLegendItem(DataPoint dataPoint, int index) { LegendItem legendItem = CreateLegendItem(); // Set the Content of the LegendItem legendItem.Content = dataPoint.IndependentValue ?? index; // Create a representative DataPoint for access to styled properties DataPoint legendDataPoint = CreateDataPoint(); legendDataPoint.Style = dataPoint.Style; legendItem.DataContext = legendDataPoint; return(legendItem); }
/// <summary> /// Creates a legend item for each data point. /// </summary> /// <param name="dataPoint">The data point added.</param> protected override void AddDataPoint(DataPoint dataPoint) { base.AddDataPoint(dataPoint); int index = ActiveDataPoints.IndexOf(dataPoint) + 1; Style style = NextStyle(typeof(PieDataPoint), true); if (dataPoint.Style == null) { dataPoint.Style = style; } LegendItem legendItem = CreatePieLegendItem(dataPoint, index); _dataPointLegendItems[dataPoint] = legendItem; LegendItems.Add(legendItem); UpdateLegendItemIndexes(); }