Profile Picture

Alignment of NLegend item's text

Posted By Igor VASILIEV 8 Years Ago
Author
Message
Igor VASILIEV
Problem Posted 8 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: 7 Years Ago
Posts: 4, Visits: 17
Hi guys,

I'm using version RSVision Vol1 2012 for VS2008.
I wanted the text on the legend to be left adjusted. On the picture it looked centered.
My idea was to iterate Data.Items property of NLegend object in RSMain method and set item's ContentAlignment propery = ContentAlignment.BottomLeft.
However I found that Data.Items has 0 items in it but chart and legend are rendered correctly.
Please advise how to achieve the desirable alignment.


https://www.nevron.com/forum/uploads/images/c0624493-ec98-4742-94a3-87e1.png


Nevron Support
Posted 8 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: 13 hours ago
Posts: 3,054, Visits: 4,009
Hi Igor,
In this case you need to use the series legend object that has a property called ContentAlignment - for example:
  NLineSeries line1 = new NLineSeries();
   line1.Legend.ContentAlignment = ContentAlignment.MiddleCenter;
   chart.Series.Add(line1);
   NLineSeries line2 = new NLineSeries();
   line2.Name = "Some Long Series Name";
   chart.Series.Add(line2);
An alternative approach is to use a legend in manual mode and specify the legend data items through code. DataItems has zero entries as the legend is populated after the chart is layout which isn't the case when the custom code is executed. Hope this helps - let us know if you meet any problems or have any questions.


Best Regards,
Nevron Support Team



Igor VASILIEV
Posted 8 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: 7 Years Ago
Posts: 4, Visits: 17
Thank you for response.
I tried the first approach. I did this in RSMain code:
bar.Legend.ContentAlignment = ContentAlignment.BottomLeft;
Value was definitely assigned but visually alignment was not changed.
I want to try the second one - a legend in manual mode. Can you point me out to the code example or demo project?



Igor VASILIEV
Posted 8 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: 7 Years Ago
Posts: 4, Visits: 17
Can you please give me some code examples how to do it using a legend in manual mode?
The first approach you suggested did not work.



Nevron Support
Posted 8 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: 13 hours ago
Posts: 3,054, Visits: 4,009
Hi Igor,

The following code shows how to add custom legend items in manual mode:

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

namespace MyNamespace
{
 /// <summary>
 /// Sample class
 /// </summary>
 public class MyClass
 {
  /// <summary>
  /// Main entry point
  /// </summary>
  /// <param name="context"></param>
  public static void RSMain(NRSChartCodeContext context)
  {
   NLegend legend = context.document.Legends[0];
   
   legend.Mode = LegendMode.Manual;

   {
    NLegendItemCellData licd = new NLegendItemCellData();
    licd.MarkLineStyle.Width = new NLength(0);
    licd.MarkFillStyle = new NColorFillStyle(Color.Red);
    licd.ContentAlignment = ContentAlignment.MiddleLeft;
    licd.Text = "Left aligned text";
    legend.Data.Items.Add(licd);
   }

   {
    NLegendItemCellData licd = new NLegendItemCellData();
    licd.MarkLineStyle.Width = new NLength(0);
    licd.MarkFillStyle = new NColorFillStyle(Color.Green);
    licd.ContentAlignment = ContentAlignment.MiddleRight;
    licd.Text = "Right aligned text";
    legend.Data.Items.Add(licd);
   }

   {
    NLegendItemCellData licd = new NLegendItemCellData();
    licd.MarkLineStyle.Width = new NLength(0);
    licd.MarkFillStyle = new NColorFillStyle(Color.Blue);
    licd.ContentAlignment = ContentAlignment.MiddleCenter;
    licd.Text = "Some long text in the middle";
    legend.Data.Items.Add(licd);
   }
  }
 }
}

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


Best Regards,
Nevron Support Team



rash Pisal
Posted 6 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: 5, Visits: 34

I'm using nevron 2011. I cant access  NLegendItemCellData licd = new NLegendItemCellData();



Nevron Support
Posted 6 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: 13 hours ago
Posts: 3,054, Visits: 4,009
Hi Rash,
Please consider to upgrade to the current release. We no longer issue support for 2011.

Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic