When converting from barchart to line chart at runtime, legend lables dissapear

4 posts, 0 answers
  1. nishan
    nishan avatar
    8 posts
    Member since:
    May 2015

    Posted 27 Mar Link to this post

    Dear Team.

     

    I am working with  RadPivotGrid and RadChartView

    I want to change from bar chart to line chart at runtime. However, when I run the line e.Series = new LineSeries(); the chart changes to line ine, but the legend lables dissapear.

    Can you please help.

    Thanks,

    Nishan

     

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    using Telerik.WinControls.UI;
    using Telerik.Charting;
    using Telerik.WinControls.UI.Export;

    namespace SizeFreq13c
    {
        public partial class RadForm1 : Telerik.WinControls.UI.RadForm
        {
            public RadForm1()
            {
                InitializeComponent();
            }

            private void RadForm1_Load(object sender, EventArgs e)
            {
                // TODO: This line of code loads data into the 'pELAGOSDataSet.Rep_SizeC' table. You can move, or remove it, as needed.
                try
                {
                this.rep_SizeCTableAdapter.Fill(this.pELAGOSDataSet.Rep_SizeC);
                radChartView1.DataSource = radPivotGrid1;
                // This event handler for pivot chart update completed
                this.radPivotGrid1.ChartDataProvider.SeriesCreating += new Telerik.WinControls.UI.SeriesCreatingEventHandler(this.ChartDataProvider_SeriesCreating);
                this.radPivotGrid1.ChartDataProvider.UpdateCompleted += new System.EventHandler(this.ChartDataProvider_UpdateCompleted);

                }
                catch (Exception Ex)
                {
                    MessageBox.Show("Most Lilely case for this error is Access is locked. Try closing and opening Access \n \n" + Ex);
                }
                

            }



            void ChartDataProvider_UpdateCompleted(object sender, EventArgs e)
            {
                    foreach (CartesianSeries series in this.radChartView1.Series)
                    {
                        switch (this.comboBox1.Text)
                        {
                            case "Cluster":
                                series.CombineMode = ChartSeriesCombineMode.Cluster;
                             break;

                            case "Stack":
                                series.CombineMode = ChartSeriesCombineMode.Stack;
                                break;

                            case "Stack100":
                                series.CombineMode = ChartSeriesCombineMode.Stack100;
                                break;

     
                        default:
                                series.CombineMode = ChartSeriesCombineMode.Cluster;
                                break;
                        }
                    }
                }

            void ChartDataProvider_SeriesCreating(object sender, Telerik.WinControls.UI.SeriesCreatingEventArgs e)
            {
               e.Series = new LineSeries();
           
            }

            private void button1_Click(object sender, EventArgs e)
            {
                {
                    PivotExportToExcelML exporter = new PivotExportToExcelML(this.radPivotGrid1);
                    exporter.ExportVisualSettings = true;
                    exporter.SheetName = "Sheet";
                    string fileName = "c:\\IOTC\\pelagos\\VesselActivity_Catch.xml";
                    exporter.RunExport(fileName);
                    try
                    {
                        exporter.RunExport(fileName);
                    }
                    catch (Exception Ex)
                    {
                        MessageBox.Show(Ex.Message);
                    }
                }
            }

            private void button2_Click(object sender, EventArgs e)
            {
                string filePath = "c:\\IOTC\\pelagos\\SizeFrequency.png";
                this.radChartView1.ExportToImage(filePath, this.radChartView1.Size, System.Drawing.Imaging.ImageFormat.Png);

            }

            private void splitContainer2_Panel1_Paint(object sender, PaintEventArgs e)
            {

            }
    //update the chart when the combo is changed
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                this.radPivotGrid1.ChartDataProvider.UpdateChartData();

            }
        }
        
    }

  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 28 Mar Link to this post

    Hello Nishan,

    Thank you for writing.

    You need to set the ShowLabels property of the new series:
    private void ChartDataProvider_SeriesCreating(object sender, SeriesCreatingEventArgs e)
    {
        e.Series = new LineSeries() { ShowLabels = true };
    }

    Let me know if you have additional questions.

    Regards,
    Dimitar
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. nishan
    nishan avatar
    8 posts
    Member since:
    May 2015

    Posted 28 Mar in reply to Dimitar Link to this post

    Dear Demitar

    Thanks for your quick responce. However it has not solved my problem. It is the lables of the Legend on the right that dissapear when I use e.Series = new LineSeries()

    Please see the attached graphic where the legend colours show but  the lables to those colours disapear when I use e.Series = new LineSeries()

    Thanks,

    Nishan.

     

  5. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 29 Mar Link to this post

    Hello Nishan,

    Thank you for writing back.

    Instead of using the event to change the series types, you can specify that by setting GeneratedSeriesType property (you can change it at runtime as well):
    this.radPivotGrid1.ChartDataProvider.GeneratedSeriesType = GeneratedSeriesType.Line;

    Let me know how this works for your case.

    Regards,
    Dimitar
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top