Profile Picture

Chart Legends

Posted By Steve Marshall 9 Years Ago
Author
Message
Steve Marshall
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: 6 Years Ago
Posts: 32, Visits: 50
Hi,

I have what I thought was a simple task, but it appears to be impossible! I am currently tasked with replacing all of the graphs in our company dashboard and am currently evaluating your Chart product. I have completed about 75% of the rework without too much in the way of issue. However, I have now got to generate a replacement for a chart that shows the status of Works Orders flowing through our systems, and the current implementation does this with a Pie Chart and a multi-column legend (showing colour from the Pie Chart, a Count, and a Percentage). The first element was quickly and easily replicated with a Torus Pie Chart which looks effective, but the latter is causing a bit of a headache.

Based on all the posts, examples, and documentation there seems to be very little control over the content and formatting of the Legend, providing only the "<value>" and "<label>" elements. This indcates immediately that I cannot replicate the three elements of the current legend .... and the Format seems very limited in that I cannot seem to even get the two allowed elements to line up in a columnar fashion. I have even asked the question about a slight change to ease the problem, and it was stated that the content of this chart has been stated as "non-variable" and MUST contain the data it does now - so no option for change!

My question (finally) is .... am I missing something (highly possible as the object model is quite extensive and I have only been working with it for a couple of days), or am I going to have to generate my own "legend" and place it on another child panel?? If the latter, how do I access the Pie Segment colours and label associations so that I can replicate these accurately in my generated legend ??

Or, is it just the case that what I need to do cannot be done .....

Thanks,
Steve


Tags
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: 3 hours ago
Posts: 3,054, Visits: 4,009
Hi Steve,
In order to achieve this you need to use a custom legend - the following example shows how to create a custom legend with three column representing color, count and percentage:

  private void Form1_Load(object sender, EventArgs e)
  {
   NLegend legend = nChartControl1.Legends[0];

   legend.Mode = LegendMode.Manual;
   legend.Data.ExpandMode = LegendExpandMode.ColsFixed;
   legend.Data.ColCount = 3;

   List<MyLegendItem> legendItems = new List<MyLegendItem>();

   legend.Data.Items.Add(CreateHeaderLegendItem("Color"));
   legend.Data.Items.Add(CreateHeaderLegendItem("Count"));
   legend.Data.Items.Add(CreateHeaderLegendItem("Percentage"));

   AddRow(legend, Color.Red, 1, 33);
   AddRow(legend, Color.Green, 2, 33);
   AddRow(legend, Color.Blue, 3, 33);
  }

  NLegendItemCellData CreateHeaderLegendItem(string text)
  {
   NLegendItemCellData data = new NLegendItemCellData();

   data.MarkShape = LegendMarkShape.None;
   data.MarkLineStyle.Width = new NLength(0);
   data.Text = text;

   return data;
  }

  private void AddRow(NLegend legend, Color color, int count, float percentage)
  {
   NLegendItemCellData data = new NLegendItemCellData();
   data.MarkShape = LegendMarkShape.Rectangle;
   data.MarkFillStyle = new NColorFillStyle(color);
   data.MarkLineStyle.Width = new NLength(0);
   legend.Data.Items.Add(data);

   data = new NLegendItemCellData();
   data.MarkShape = LegendMarkShape.None;
   data.MarkLineStyle.Width = new NLength(0);
   data.Text = count.ToString();
   legend.Data.Items.Add(data);

   data = new NLegendItemCellData();
   data.MarkShape = LegendMarkShape.None;
   data.MarkLineStyle.Width = new NLength(0);
   data.Text = percentage.ToString();
   legend.Data.Items.Add(data);
  }

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




Best Regards,
Nevron Support Team



Steve Marshall
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: 6 Years Ago
Posts: 32, Visits: 50
Thanks for the quick response - I will give this a go and come back to you if there are any issues.

Steve


Steve Marshall
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: 6 Years Ago
Posts: 32, Visits: 50
Hi there. Great news - 98% of the way there and it is looking good. Just a few more questions to get me the last few steps:

1. How do I programattically tie the colour passed to the Row Add function to the colour assigned to the pie chart segment. I suppose what I am asking here is how after I have added the Data Point to my series can I retrieve the colour that has been assigned to that segment. Alternatively, how do I force a colour to a segment as I add it, which would achieve the same thing?

2. How do I suppress some/all of the Grid Lines displayed in the legend ?

3. How do I position the text within the cells ? Is there a ContentAlignment attribute like elsewhere ?

Thanks,
Steve


Steve Marshall
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: 6 Years Ago
Posts: 32, Visits: 50
Forget point #3 - I just found the ContentAlignment property of the NLegendItemCellData!!

I clearly did not look properly - Apologies.

Steve

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: 3 hours ago
Posts: 3,054, Visits: 4,009
Hi Steve,

1. How do I programattically tie the colour passed to the Row Add function to the colour assigned to the pie chart segment. I suppose what I am asking here is how after I have added the Data Point to my series can I retrieve the colour that has been assigned to that segment. Alternatively, how do I force a colour to a segment as I add it, which would achieve the same thing?

That depends on how you assign colors to the pie:

1. If you don't assign colors explicitly (using the pie.FillStyles collection) the color of the pie is the value of the pieSeries.FillStyle property.
2. If you assign the colors to the pie using a style sheet then the stylesheet must be applied before you can get the fill style of the of the pie.

The following code shows how to create a pie chart with three slices (red, green, blue):

   NPieChart pieChart = new NPieChart();

   NPieSeries pieSeries = new NPieSeries();

   pieSeries.Values.Add(10);
   pieSeries.FillStyles[0] = new NColorFillStyle(Color.Red);

   pieSeries.Values.Add(20);
   pieSeries.FillStyles[1] = new NColorFillStyle(Color.Green);

   pieSeries.Values.Add(30);
   pieSeries.FillStyles[2] = new NColorFillStyle(Color.Blue);

   pieChart.Series.Add(pieSeries);

   nChartControl1.Panels.Add(pieChart);

You can later retrieve the fill style usings the FillStyles collection:

// get the fill style of the second slice
NFillStyle fillStyle = (NFillStyle)pieSeries.FillStyles[1];

In order to assing that fill to the marker fill you'll have to clone it:

data.MarkFillStyle = (NFillStyle)fillStyle.Clone();

2. How do I suppress some/all of the Grid Lines displayed in the legend ?

The following code shows how to suppress all borders:

// inner grid lines
legend.VerticalBorderStyle.Width = new NLength(0);
legend.HorizontalBorderStyle.Width = new NLength(0);

// outer border
legend.OuterLeftBorderStyle.Width = new NLength(0);
legend.OuterTopBorderStyle.Width = new NLength(0);
legend.OuterRightBorderStyle.Width = new NLength(0);
legend.OuterBottomBorderStyle.Width = new NLength(0);

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


Best Regards,
Nevron Support Team



Steve Marshall
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: 6 Years Ago
Posts: 32, Visits: 50
Apologies for the delay, I have been working away for a few weeks with no access to my PC on which I was developing.

I have now hidden my legend grid lines using your reply (thanks), and have increased the space between columns by adding "dummy" columns, but is there a "better" way of doing this? I have looked for a margins on the cells etc but can see nothing obvious. I have also tried padding the headers with spaces, but when processed the values are obviously trimmed so this achieved nothing.

Also, I am struggling to retrieve the fillstyle for the added data-point as there seems to be none in the collection even after adding the data-point (working in debug and interrogating the Fillstyles). I have created a legend based on the earlier reply from Nevron Support, and then I retrieve my data via a Data Table and then post the values into the Pie Series with:

PieSeries.AddDataPoint(New NDataPoint(StatusPercent, StatusText))

I then call my routine to add the relevant entry into the legend, and I pass all of the relevant details into the routine as parameters. It is at this point that I want to know the colour that is applied to that segment. I think, though that it may not be possible to get the colour here as a style sheet is applied later and I guess that this applies the colours:

Dim PieSheet As NStyleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.BrightMultiColor)    
PieSheet.Apply(TheChart.Document)    
TheChart.Refresh()

I think I am trying to do things in the wrong order .....

Also, another question (related to the NChartControl) - is there a way to turn the borders off on that ? I have looked for similar properties to those on the legend, but if they are there (which I am sure they must be), they must be somewhere I am not looking!

Apologies for all the newbie questions - I am evaluating the capabilities prior to purchase and need to make sure all of the gripes from the users can be addressed.

Thanks
Steve



Steve Marshall
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: 6 Years Ago
Posts: 32, Visits: 50
Hi,

Just a quick note to let you know that I have found ways to address theae two issues.

The colours problem I have solved by extending my data tables and queries to return RGB values along with the data and then my code uses these to create a Color object which is used to set the FillStyle for the segment and legend row.

The borders issue I just used a trick. Each chart was placed in a standard WinForms Panel, located at -1,-1 and sized at the panel dimensions + 2 in both height and width. As such, the border becomes invisible as it is outside the display area of the panel.

For this last one, please let me know if there is a way to directly hide the border of the control and I will remove this trick. For the time being though, I have met the requirements of my users this way.

Thanks,
Steve


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: 3 hours ago
Posts: 3,054, Visits: 4,009
Hi Steve,

To hide the border around the control you can use:
nChartControl1.BackgroundStyle.FrameStyle.Visible = false;

Let us know if you meet any problems or have any questions.


Best Regards,
Nevron Support Team



Steve Marshall
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: 6 Years Ago
Posts: 32, Visits: 50
Thanks, that has done it. I knew there had to be a way. It is just going to take a while to get my head around the object model and the property lists because to do a particular thing the property name seems to depend on the object even though you are in effect doing the same thing - such as hiding the border.

Thanks again,
Steve





Similar Topics


Reading This Topic