Hi,
I am creating a sales chart that will show daily sales within a period of time.
So I have two RadCalendars one to choose the FROM date and another to choose the To date.
I have a method that return all sales between the date selected on the FROM calendar and the date + 1 day of the TO calendar and then sets the item source for the RadChart like this:
private void LoadSales(int _chatType, int _storeId)
{
StoreSaleContext ctx = new StoreSaleContext();
chtSalesChart.ItemsSource = ctx.StoreSales;
ctx.Load(ctx.GetStoreSalesbyDateRangeQuery(_storId, Convert.ToDateTime(datePickerFrom.SelectedDate.Value.ToString()), Convert.ToDateTime(datePickerTo.SelectedDate.Value.AddDays(1).ToString())));
switch (_chatType)
{
case 1:
SetChartBar();
break;
case 2:
SetCharLinear();
break;
default:
SetChartBar();
break;
}
}
At this point everything works just fine.
The problem is when I try to customize the X Axis to show a bar for each of the sales in a x Axis space.
As you can see I have a SetCharBar method that looks like this:
private void SetChartBar()
{
CustomizeChartBars();
chtSalesChart.DefaultView.ChartTitle.HorizontalAlignment = HorizontalAlignment.Center;
chtSalesChart.DefaultView.ChartTitle.Content = "Daily Sales";
var seriesMapping = new SeriesMapping();
seriesMapping.LegendLabel = "Daily Sales";
seriesMapping.SeriesDefinition = new BarSeriesDefinition();
var itemMapping = new ItemMapping("NetSales", DataPointMember.YValue);
seriesMapping.ItemMappings.Clear();
chtSalesChart.SeriesMappings.Clear();
seriesMapping.ItemMappings.Add(itemMapping);
chtSalesChart.SeriesMappings.Add(seriesMapping);
}
It works fine excepts for the CustomizeChartBars(); method:
//Here is my issue
private void CustomizeChartBars()
{
chtSalesChart.DefaultView.ChartArea.AxisX.IsDateTime = true;
chtSalesChart.DefaultView.ChartArea.AxisX.AutoRange = false;
chtSalesChart.DefaultView.ChartArea.AxisX.MinValue = datePickerFrom.SelectedDate.Value.ToOADate();
chtSalesChart.DefaultView.ChartArea.AxisX.MaxValue = datePickerTo.SelectedDate.Value.ToOADate();
chtSalesChart.DefaultView.ChartArea.AxisX.Step = DateTime.Today.AddDays(1).ToOADate() - DateTime.Today.ToOADate();
chtSalesChart.DefaultView.ChartArea.AxisX.LabelRotationAngle = 45;
}
As you can see I have set the min a max values to the FROM and TO RadCalendars respectively and 1 as the step.
Notice also that max values is not + 1, this is because I just need that when retrieving the data from the database.
Lets say I choose this range from 08/03/2009 to 08/07/009 The problem is when I run it, what it shows at the Chart are only 4 sales when I have 5 and the bars are not at the center of the x space some of them use more than one x space.
I tried changing the range like this: 08/03/2009 to 08/08/009 and it shows all the sales I have but obviously it adds another x space for Saturday and that's not what I want.
Something else that is wrong for example, if I vary the range again like this: 08/01/2009 to 08/08/009 it shows all the sales but it starts at the 08/01/2009 and this is not correct.
How can I customize the chart so sales will be shown at the date they were made and bars will use only one x space at the chart and not half and half like is doing now.
Thanks in Advance for the your help
The happy Lemur
I am creating a sales chart that will show daily sales within a period of time.
So I have two RadCalendars one to choose the FROM date and another to choose the To date.
I have a method that return all sales between the date selected on the FROM calendar and the date + 1 day of the TO calendar and then sets the item source for the RadChart like this:
private void LoadSales(int _chatType, int _storeId)
{
StoreSaleContext ctx = new StoreSaleContext();
chtSalesChart.ItemsSource = ctx.StoreSales;
ctx.Load(ctx.GetStoreSalesbyDateRangeQuery(_storId, Convert.ToDateTime(datePickerFrom.SelectedDate.Value.ToString()), Convert.ToDateTime(datePickerTo.SelectedDate.Value.AddDays(1).ToString())));
switch (_chatType)
{
case 1:
SetChartBar();
break;
case 2:
SetCharLinear();
break;
default:
SetChartBar();
break;
}
}
At this point everything works just fine.
The problem is when I try to customize the X Axis to show a bar for each of the sales in a x Axis space.
As you can see I have a SetCharBar method that looks like this:
private void SetChartBar()
{
CustomizeChartBars();
chtSalesChart.DefaultView.ChartTitle.HorizontalAlignment = HorizontalAlignment.Center;
chtSalesChart.DefaultView.ChartTitle.Content = "Daily Sales";
var seriesMapping = new SeriesMapping();
seriesMapping.LegendLabel = "Daily Sales";
seriesMapping.SeriesDefinition = new BarSeriesDefinition();
var itemMapping = new ItemMapping("NetSales", DataPointMember.YValue);
seriesMapping.ItemMappings.Clear();
chtSalesChart.SeriesMappings.Clear();
seriesMapping.ItemMappings.Add(itemMapping);
chtSalesChart.SeriesMappings.Add(seriesMapping);
}
It works fine excepts for the CustomizeChartBars(); method:
//Here is my issue
private void CustomizeChartBars()
{
chtSalesChart.DefaultView.ChartArea.AxisX.IsDateTime = true;
chtSalesChart.DefaultView.ChartArea.AxisX.AutoRange = false;
chtSalesChart.DefaultView.ChartArea.AxisX.MinValue = datePickerFrom.SelectedDate.Value.ToOADate();
chtSalesChart.DefaultView.ChartArea.AxisX.MaxValue = datePickerTo.SelectedDate.Value.ToOADate();
chtSalesChart.DefaultView.ChartArea.AxisX.Step = DateTime.Today.AddDays(1).ToOADate() - DateTime.Today.ToOADate();
chtSalesChart.DefaultView.ChartArea.AxisX.LabelRotationAngle = 45;
}
As you can see I have set the min a max values to the FROM and TO RadCalendars respectively and 1 as the step.
Notice also that max values is not + 1, this is because I just need that when retrieving the data from the database.
Lets say I choose this range from 08/03/2009 to 08/07/009 The problem is when I run it, what it shows at the Chart are only 4 sales when I have 5 and the bars are not at the center of the x space some of them use more than one x space.
I tried changing the range like this: 08/03/2009 to 08/08/009 and it shows all the sales I have but obviously it adds another x space for Saturday and that's not what I want.
Something else that is wrong for example, if I vary the range again like this: 08/01/2009 to 08/08/009 it shows all the sales but it starts at the 08/01/2009 and this is not correct.
How can I customize the chart so sales will be shown at the date they were made and bars will use only one x space at the chart and not half and half like is doing now.
Thanks in Advance for the your help
The happy Lemur