Hi All,
I am using WPF RadChart , to create and export charts in code behind, everything is ok in all chart type same as bubble , pie , linear, … but in Bar chart using BarSeriesDefinition, the exported Image has no bar! Labels are shown correctly above hidden bars! Also created chart is shown correctly in WPF RadChart.
in this below code I show the problem
Regards
I am using WPF RadChart , to create and export charts in code behind, everything is ok in all chart type same as bubble , pie , linear, … but in Bar chart using BarSeriesDefinition, the exported Image has no bar! Labels are shown correctly above hidden bars! Also created chart is shown correctly in WPF RadChart.
in this below code I show the problem
Regards
private void Button_Click(object sender, RoutedEventArgs e) { ChartBaseParameter ChartParam = new ChartBaseParameter() { XAxisField = "x", YAxisFields = new List<string>() { "y" } }; DataTable dt = new DataTable(); dt.Columns.Add("x", typeof(int)); dt.Columns.Add("y", typeof(int)); dt.Rows.Add(1, 1); dt.Rows.Add(2, 2); this.ChartPanel.SeriesMappings.Clear(); this.ChartPanel.SortDescriptors.Clear(); this.ChartPanel.ItemsSource = null; var chart = InitChart(this.ChartPanel, ChartParam, true, dt); var fileName = "C:\\myChart.jpg"; chart.ExportToImage(fileName, new PngBitmapEncoder()); } public static RadChart InitChart(RadChart chartPanel, ChartBaseParameter chartParam, bool showError, System.Data.DataTable chartTable) { bool showItemLabels = true; AnimationManager.IsGlobalAnimationEnabled = false; chartPanel.DefaultView.ChartArea.EnableAnimations = false; chartPanel.BeginInit(); chartPanel.Width = 300; chartPanel.Height = 300; BarLabelSettings barLabelSetting = new BarLabelSettings(); barLabelSetting.Distance = 10; barLabelSetting.LabelDisplayMode = LabelDisplayMode.Outside; barLabelSetting.ShowConnectors = true; foreach (var YItem in chartParam.YAxisFields) { SeriesMapping seriesmappingi = new SeriesMapping() { LegendLabel = YItem }; seriesmappingi.SeriesDefinition = new BarSeriesDefinition() { ShowItemLabels = showItemLabels, LabelSettings = barLabelSetting }; seriesmappingi.ItemMappings.Add(new ItemMapping("y", DataPointMember.YValue) { FieldType = typeof(int) }); seriesmappingi.ItemMappings.Add(new ItemMapping("x", DataPointMember.XCategory) { FieldType = typeof(int) }); seriesmappingi.ItemMappings.Add(new ItemMapping("x", DataPointMember.LegendLabel) { FieldType = typeof(int) }); chartPanel.SeriesMappings.Add(seriesmappingi); } chartPanel.DefaultView.ChartArea.AxisX.LabelRotationAngle = -90; chartPanel.DefaultView.ChartArea.ZoomScrollSettingsX.MinZoomRange = 0.01; chartPanel.DefaultView.ChartArea.AxisX.Title = chartParam.XAxisField; chartPanel.DefaultView.ChartArea.ZoomScrollSettingsX.ScrollMode = ScrollMode.ScrollAndZoom; chartPanel.DefaultView.ChartArea.AxisY.ExtendDirection = AxisExtendDirection.Both; chartPanel.DefaultView.ChartArea.LabelFormatBehavior = LabelFormatBehavior.None; chartPanel.DefaultSeriesDefinition.LegendDisplayMode = LegendDisplayMode.DataPointLabel; chartPanel.EndInit(); chartPanel.Measure(new Size(1024, 768)); chartPanel.Arrange(new System.Windows.Rect(new Point(0, 0), chartPanel.DesiredSize)); chartPanel.ItemsSource = chartTable; chartPanel.Rebind(); chartPanel.UpdateLayout(); return chartPanel; } } public class ChartBaseParameter { public string XAxisField; public List<string> YAxisFields; }