ObservableCollection<ReportingDatapointDate> reportData =
new
ObservableCollection<ReportingDatapointDate>();
// Vaules taken from Web Service ...
SeriesMapping seriesMapping =
new
SeriesMapping
{
LegendLabel =
"Test Data"
,
SeriesDefinition =
new
BarSeriesDefinition{
InteractivitySettings ={
SelectionScope =InteractivityScope.Series,
HoverScope =InteractivityScope.Series,
SelectionMode =ChartSelectionMode.Single
}
}
};
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"DateTimeAxisValue"
, DataPointMember.XValue));
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"NumberAxisValue"
, DataPointMember.YValue));
chart.SeriesMappings.Add(seriesMapping);
chart.ItemsSource = reportData;
public
class
ReportingDatapointDate
{
public
DateTime DateTimeAxisValue {
get
;
set
; }
public
double
NumberAxisValue {
get
;
set
; }
}
6 Answers, 1 is accepted
Dates, displayed in your X-axis, are repeated because you are adding your DateTime objects as X values. This causes the axis to go into strict mode in which the items are drawn from Min to Max using a calculated step.
Try using XCategory as your DataPoint.Member instead of using XValue. More about categorical charts can be found here.
Regards,
Peshito
the Telerik team
Thank you so much that's been driving me crazy !
Richard
Thanks
Rahul
Please refer to our online help topic here where you can find more about empty values behavior.
You can also take a look at our online demo example:
http://demos.telerik.com/silverlight-old/#Chart/EmptyValues
Hope this helps.
All the best,
Peshito
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
Thanks for replying. Any help in solving this issue asap will be great. I am attaching two images. The one I have used XCategory which groups the dates for 2 items. Suppose if you have to items you want it to draw then it will group 2 items by date and if one of the item does not have value on that day then it puts that items values at the last which I do not want. Please take a look at the images and below code also.
1> not desired one.
2> desired result.
Below is the xaml--
<
telerik:RadChart Grid.Row="1" Grid.ColumnSpan="2" x:Name="radTimeGraph" ItemsSource="{Binding Job_TimeSeries,Mode=OneWay}"
Background="Transparent" BorderBrush="{x:Null}"
HorizontalAlignment="Left" Margin="0,0,5,0" SeriesMappings="{Binding ChartSeriesMapping}"
VerticalAlignment="Top"
Visibility="{Binding ChartVisibility}">
<
telerik:RadChart.DefaultView>
<telerik:ChartDefaultView ChartLegendPosition="Right">
<telerik:ChartDefaultView.ChartLegend>
<telerik:ChartLegend x:Name="chartLegend" Header="" UseAutoGeneratedItems="True"
MouseLeftButtonUp="chartLegend_MouseLeftButtonUp"
LegendItemStyle="{StaticResource LegendItemStyle}"
HorizontalAlignment="Center"
Background="Transparent" BorderBrush="{x:Null}" FontWeight="Bold"
/>
</telerik:ChartDefaultView.ChartLegend>
<telerik:ChartDefaultView.ChartArea>
<telerik:ChartArea LegendName="chartLegend" ItemToolTipOpening="ChartArea_ItemToolTipOpening">
<telerik:ChartArea.AxisY>
<telerik:AxisY Title="Elapse Mins. (in min)" StripLinesVisibility="Collapsed"/>
</telerik:ChartArea.AxisY>
<telerik:ChartArea.AxisX>
<telerik:AxisX Title="Cycle Date"
LabelRotationAngle="-70" DefaultLabelFormat="dd MMM" />
</telerik:ChartArea.AxisX>
</telerik:ChartArea>
</telerik:ChartDefaultView.ChartArea>
</telerik:ChartDefaultView>
</telerik:RadChart.DefaultView>
</
telerik:RadChart>
view model code--
private
void AddSeriesMapping()
{
ChartSeriesMapping =
new SeriesMappingCollection();
if (item_Series != null && item_Series.Count > 0)
{
foreach (var series_data in originalData)
{
ChartSeriesMapping.Add(GetSeries(series_data ));
}
}
}
private
SeriesMapping GetSeries(series_data jobTS_data)
{
SeriesMapping series = new SeriesMapping();
series.ItemsSource = jobTS_data.TSData;
int range = (Convert.ToDateTime(EndDate) - Convert.ToDateTime(StartDate)).Days;
series.LegendLabel = jobTS_data.TSData.FirstOrDefault().UniqueJobIdParentID;
 
SeriesDefinition seriesDef = null;
switch (SelectedChartType)
{
case "Bar":
seriesDef =
new BarSeriesDefinition() { ShowItemLabels = Util.SHOW_ITEM_LABEL };
break;
case "Line":
seriesDef =
new LineSeriesDefinition()
{
ShowItemLabels =
Util.SHOW_ITEM_LABEL,
EmptyPointBehavior =
EmptyPointBehavior.Drop,
};
break;
case "Scatter":
seriesDef =
new ScatterSeriesDefinition()
{
ShowItemLabels =
Util.SHOW_ITEM_LABEL
};
break;
}
seriesDef.ShowItemToolTips =
true;
series.SeriesDefinition = seriesDef;
series.ItemMappings.Add(
new ItemMapping() { DataPointMember = DataPointMember.YValue, FieldName = "Minutes" });
series.ItemMappings.Add(
new ItemMapping() { DataPointMember = DataPointMember.XValue, FieldName = "Date"});
IsStatsExpanded =
false;
return series;
}
As my colleague Evgenia has already replied in the other forum thread you have here, if you need to enforce strict ordering of items on the XAxis, you'll need to sort the XCategories before providing them to the chart.
I would also suggest to keep the conversation in a single thread so it is easier for both sides to follow.
Kind regards,
Peshito
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.