protected override void GenerateChart()
{
RootElement.Children.Clear();
var data = ItemsSource;
if (data != null && data.Any())
{
double max = Math.Max(0, data.Values.Max());
double min = Math.Min(0, data.Values.Min());
Range dataRange = new Range(min, max);
// Get the label values
var labels = BarChart.GetLabelValues(dataRange, MaxLabel).ToArray();
// The label might be out of the current range (e.g if max value = '99', there will be a label '100')
// Extend the range to include the labels
dataRange.Min = Math.Min(dataRange.Min, labels.Min());
dataRange.Max = Math.Max(dataRange.Max, labels.Max());
// Create chart main structure
GenerateChartStructure(dataRange);
// Generate the labels
foreach (double val in labels)
GenerateLabel(val, dataRange);
// Generate data points
GenerateDataPoints(data, dataRange);
}
}