Profile Picture

Pie Chart - Label Mode

Posted By Jerry Jacob 9 Years Ago
Author
Message
Jerry Jacob
Question Posted 9 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 9 Years Ago
Posts: 15, Visits: 78
Is there a way to change the labelmode based on the data?

Something along the lines of

     
if (pieSeries.Values[i] > .1){
        //I want to change the labelMode of this value to Center on the pie chart
        pieSeries.LabelMode = PieLabelMode.Center;
       }else {
        //I want to change the labelMode of this value to SpiderNoOverlap on the pie chart
        pieSeries.LabelMode = PieLabelMode.SpiderNoOverlap;
       }


Also how can I adjust the lengths of the lines for SpiderNoOverlap.  I tried the following without success.

      pieSeries.DataLabelStyle.ArrowLength = new NLength(1.0f,NRelativeUnit.ParentPercentage);
      pieSeries.DataLabelStyle.ArrowPointerLength = new NLength(1.0f,NRelativeUnit.ParentPercentage);





Nevron Support
Posted 9 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Yesterday @ 1:54 AM
Posts: 3,054, Visits: 4,009
Hi Jerry,

You can control the length of the connectors using the LeadOffArrowLength and ConnectorLength properties of the pie series (the lines that connect pie sectors with their data labels consist of several parts). As for the labels - all labels in the pie use the same style so there is no way to mix them. Hope this helps let us know if you meet any problems or have any questions.

Best Regards,
Nevron Support Team



Jerry Jacob
Posted 9 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 9 Years Ago
Posts: 15, Visits: 78
I have tried

      pieSeries.LabelMode = PieLabelMode.SpiderNoOverlap;
       pieSeries.LeadOffArrowLength = new NLength(0.25f);
       pieSeries.ConnectorLength = new NLength(0.25f);

And changed the length to be different numbers but I haven't noticed any change in the size of the line.

Nevron Support
Posted 9 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Yesterday @ 1:54 AM
Posts: 3,054, Visits: 4,009
Hi Jerry,

Probably you started experimenting with zero value - that's why you don't see a difference - try to insert larger values - like 10, 12, 15... etc.


Best Regards,
Nevron Support Team



Jerry Jacob
Posted 9 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 9 Years Ago
Posts: 15, Visits: 78
I tried different ranges of numbers, however for my current situation I am trying to make the lines smaller which does not seem to be working.

The problem stems from not being able to switch the Label mode, because if I use center, there are some pie pieces that are too small for the text, and if i use spider then the chart shrinks to allow the words to appear on the side and then the chart is too small.

Do you have any suggestions on how to try to get around this so that it can work out?  I was considering trying to make a whole new pie series for each piece so that way theoretically they would have independent labelmodes.  Would that work?  If so, what would be the best way to do that.  I figured if there was a way to get the percentage of each block, then basically transform each pie piece to its own series with that percentage as the max for the pie and let it consume the whole thing.




Nevron Support
Posted 9 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Yesterday @ 1:54 AM
Posts: 3,054, Visits: 4,009
Hi Jerry,
One solution would be to use anchor panels for the labels that you wish to exclude from automatic layout. The following code snippet shows how to achieve this:

   nChartControl1.Panels.Clear();

   NPieChart pieChart = new NPieChart();

   nChartControl1.Panels.Add(pieChart);

   NPieSeries pieSeries = new NPieSeries();
   pieChart.Series.Add(pieSeries);

   pieSeries.Values.Add(10);
   pieSeries.Values.Add(10);
   pieSeries.Values.Add(10);
   pieSeries.LabelMode = PieLabelMode.SpiderNoOverlap;

   pieSeries.Labels.Add("One");
   pieSeries.Labels.Add("");
   NDataLabelStyle dls = new NDataLabelStyle();
   dls.Visible = false;
   pieSeries.DataLabelStyles[1] = dls;
   pieSeries.Labels.Add("Three");

   NLabel label = new NLabel("Two");
   label.ContentAlignment = ContentAlignment.MiddleCenter;
   label.TextStyle = (NTextStyle)dls.TextStyle.Clone();
   NAnchorPanel anchorPanel = new NAnchorPanel();
   anchorPanel.ChildPanels.Add(label);
   anchorPanel.Anchor = new NPieDataPointAnchor(pieSeries, 1, 1, StringAlignment.Center);

   nChartControl1.Panels.Add(anchorPanel);

Hope this helps - let us know if you meet any problems or have any questions.


Best Regards,
Nevron Support Team



Jerry Jacob
Posted 9 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 9 Years Ago
Posts: 15, Visits: 78
This may be a silly question but how do I get a NChartControl in to the chart? I can't seem to find it.

Thanks!

Nevron Support
Posted 9 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Yesterday @ 1:54 AM
Posts: 3,054, Visits: 4,009
Hi Jerry,

The NChartControl instance (nChartControl) is automatically created by the designer when you drop the control on the form. Your control can have a different name of course... Let us know if you meet any problems.


Best Regards,
Nevron Support Team



Jerry Jacob
Posted 9 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 9 Years Ago
Posts: 15, Visits: 78
Where would I find the name though?  Under properties I see NChart1, but when I try using it I get an error

Compiling...
(25,13) : error CS0103: The name 'NChart1' does not exist in the current context
Compiled with 1 error(s).

Not sure if its because of how I have the code set up referencing context in the RSMain, but not sure how to adjust it to do what we are trying.

I pasted the code below in case it will help in solving this.  I really appreciate your efforts on this.

Thanks,

using System;
using System.Drawing;
using Nevron.GraphicsCore;
using Nevron.Chart;
using Nevron.ReportingServices;
using System.Text.RegularExpressions;

namespace MyNamespace
{
  public class MyClass
  {
    public static void RSMain(NRSChartCodeContext context)
    {
    
      if (context.document.Charts.Count == 0)
        return;
        
     NChart1.Panels.Clear();
      NPieChart pieChart = context.document.Charts[0] as NPieChart;
      
      if (pieChart == null)
        return;
        
      NPieSeries pieSeries = pieChart.Series[0] as NPieSeries;
    
      int dpCount = pieSeries.Values.Count / 2;
      int backColorOffset = dpCount;

      for (int i = 0; i < dpCount; i++)
      {
      string strColors = (string)pieSeries.Labels[backColorOffset+i];
      if (strColors == "") {
      strColors = "0,0,0";
      }
      char[] delimiterChars = {','};
      string[] intColors = strColors.Split(delimiterChars);
      int[] convertedItems = Array.ConvertAll<string, int>(intColors, int.Parse);
      
       Color pieColor = Color.FromArgb(convertedItems[0],convertedItems[1],convertedItems[2]);
       Color pieColor_White = Color.FromArgb(255,255,255);
      
       pieSeries.FillStyles[i] = new NColorFillStyle(pieColor);
       pieSeries.BorderStyles[i] = new NStrokeStyle(.1f, pieColor_White);
       pieSeries.DataLabelStyle.ArrowStrokeStyle = new NStrokeStyle(pieColor);
     
      }
      
      // clean up the chart
      for (int i = pieSeries.Values.Count - 1; i >= dpCount; i--)
      {
        pieSeries.RemoveDataPointAt(i);
      }
    }
  }
}




Nevron Support
Posted 9 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Yesterday @ 1:54 AM
Posts: 3,054, Visits: 4,009
Hi Jerrry,

This obviously relates to SSRS - in this case you simply need to use the context.Document, instead of nChartControl and you'll be OK - for example:

context.document.RootPanel.ChildPanels.Clear();

However in your case we think that you should not clear the panels collection - the pie chart is already created and configured - you just need to alter some label settings so the code should simply omit the Clear line of code:

NChart1.Panels.Clear();

Hope this helps - let us know if you meet any problems or have any questions.


Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic