[C#] //Replace the text with custom string values of all legend items in pie chart foreach (ChartLegendItem item in this.chartControl1.Legend.Items) { //LegendItem.Children is not null only for pie series or accumulation type series int pointIndex = series.LegendItem.Children.IndexOf(item); if (pointIndex != -1) { //Customize the text displayed in legend item //You can use any string as value item.Text = series.Points[pointIndex].Category; } else //This is the case for first point in chart series item.Text = series.Points[0].Category; //Customizing the text color of legend item item.TextColor = Color.Black; } |
[C#] //Display label for points series.Style.DisplayText = true; |
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Syncfusion.Chart.Base
StackTrace:
at Syncfusion.Windows.Forms.Chart.ChartSeriesRenderer.PrepearePoints()
at Syncfusion.Windows.Forms.Chart.ChartSeriesRenderer.CanRender()
at Syncfusion.Windows.Forms.Chart.ChartPlace.CalculateSpace(ChartSeriesCollection series, Boolean doManyAreas, IChartAreaHost chart)
at Syncfusion.Windows.Forms.Chart.ChartSeriesCollection.DrawSeries(Graphics g, IChartAreaHost chart)
at Syncfusion.Windows.Forms.Chart.ChartArea.Draw2D(PaintEventArgs e, ChartPaintFlags flags)
at Syncfusion.Windows.Forms.Chart.ChartArea.Draw(PaintEventArgs e, ChartPaintFlags flags)
at Syncfusion.Windows.Forms.Chart.ChartControl._Paint(Graphics g, Rectangle r)
at Syncfusion.Windows.Forms.Chart.ChartControl.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at Syncfusion.Windows.Forms.Chart.ChartControl.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
[C#] //Setting X-axis for chart series series.XAxis = this.chartControl1.PrimaryXAxis; |