This is a migrated thread and some comments may be shown as answers.

Exporting BarChart

3 Answers 88 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Ghasem
Top achievements
Rank 1
Ghasem asked on 25 Dec 2014, 08:15 AM
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


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;
    }

3 Answers, 1 is accepted

Sort by
0
Peshito
Telerik team
answered on 26 Dec 2014, 02:59 PM
Hello,

What you can try is first disabling all animations:
Copy Code
chart.DefaultView.ChartArea.EnableAnimations = false;
Also, when using bar series you will need to set an ItemStyle to the bar SeriesDefinition which excludes animations specific to the Bars.

Hope this helps.


Regards,
Peshito
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ghasem
Top achievements
Rank 1
answered on 27 Dec 2014, 07:35 AM
thank you for your reply , but i don't know which property I should use to exclude animation, I try below but it doesn't work
seriesmappingi.SeriesDefinition = new BarSeriesDefinition()
                                {
                                    ShowItemLabels = showItemLabels,
                                    AnimationSettings = new AnimationSettings()
                                    {
                                        DefaultSeriesDelay = TimeSpan.Zero,
                                        TotalSeriesAnimationDuration = TimeSpan.Zero,
                                        ItemAnimationDuration = TimeSpan.Zero,
                                        ItemDelay = TimeSpan.Zero
                                    }
                                };
0
Petar Marchev
Telerik team
answered on 31 Dec 2014, 01:57 PM
Hi Ghasem,

The trick to exporting a bar chart is setting a style in which the animations have been removed, just as mentioned earlier. I have attached a simple project which successfully exports a bar chart. You will find the bar ItemStyle in the code. I hope this helps.

Regards,
Petar Marchev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Chart
Asked by
Ghasem
Top achievements
Rank 1
Answers by
Peshito
Telerik team
Ghasem
Top achievements
Rank 1
Petar Marchev
Telerik team
Share this question
or