Showing Trend Marks in C1Chart

The following example code shows how to use the trend indicators in the chart with triangles used as arrows:

      Visual Basic

      C#

Using Automatic Series Generation

The following feature is useful in various MVVM scenarios and allows you to automatically generate series based on a provided template.

Use the following XAML for a chart declaration:

<c1:C1Chart Name="chart">
<c1:C1Chart.DataContext>
<!-- sample data -->
<local:ChartData />
</c1:C1Chart.DataContext>
<c1:C1Chart.Data>
<c1:ChartData SeriesItemsSource="{Binding SeriesDataCollection}" >
<c1:ChartData.SeriesItemTemplate>
<!-- template for series -->
<DataTemplate>
<c1:DataSeries Label="{Binding Name}"
ValuesSource="{Binding Values}" />
</DataTemplate>
</c1:ChartData.SeriesItemTemplate>
</c1:ChartData>
</c1:C1Chart.Data>
<c1:C1ChartLegend />
</c1:C1Chart>

 

Then use the following code for a sample data model:

public class ChartData
{
public static int NUM_SERIES = 5;

public ObservableCollection<SeriesData> SeriesDataCollection
{
get
{
if (_seriesDataCollection == null)
{
_seriesDataCollection =
new ObservableCollection<SeriesData>();
for (int i = 0; i < NUM_SERIES; i++)
_seriesDataCollection.Add(new SeriesData("Series " + i));
}
return _seriesDataCollection;
}
}
private ObservableCollection<SeriesData> _seriesDataCollection;
}

public class SeriesData
{
static int NUM_POINTS = 10;
static Random rnd = new Random();

public SeriesData(string name)
{
Name = name;

Values = new double[NUM_POINTS];
for (int i = 0; i < NUM_POINTS; i++)
Values[i] = rnd.Next(0, 100);
}

public string Name { get; set; }
public double[] Values { get; set; }
}


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.