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

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

3 Answers 86 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
nishan
Top achievements
Rank 1
nishan asked on 28 Mar 2016, 12:46 AM

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();

        }
    }
    
}

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 28 Mar 2016, 08:38 AM
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.
0
nishan
Top achievements
Rank 1
answered on 28 Mar 2016, 02:54 PM

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.

 

0
Dimitar
Telerik team
answered on 29 Mar 2016, 10:20 AM
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.
Tags
ChartView
Asked by
nishan
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
nishan
Top achievements
Rank 1
Share this question
or