Profile Picture

Overlap a axis's label

Posted By inhyuk son 14 Years Ago
Author
Message
inhyuk son
Posted 14 Years Ago
View Quick Profile
Junior Member

Junior Member (21 reputation)Junior Member (21 reputation)Junior Member (21 reputation)Junior Member (21 reputation)Junior Member (21 reputation)Junior Member (21 reputation)Junior Member (21 reputation)Junior Member (21 reputation)Junior Member (21 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 21, Visits: 1
Hi~
I try to avoid to overlap a axis's label using LabelFitMode.RemoveOverlap.
But it is delayed applying.

My code and a screenshot is here.
Thanks for your help.



private void RemoveOverlapLabel()
{
NChart m_Chart = nChartControl1.Charts[0];
m_Chart.BoundsMode = BoundsMode.Stretch;

NStandardScaleConfigurator scaleConfiguratorX = (NStandardScaleConfigurator)m_Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator;
//scaleConfiguratorX.MajorTickMode = MajorTickMode.CustomStep;

scaleConfiguratorX.LabelFitModes = new LabelFitMode[] { LabelFitMode.RemoveOverlap };

scaleConfiguratorX.AutoLabels = false;
scaleConfiguratorX.Labels.Add("France");
scaleConfiguratorX.Labels.Add("Italy");
scaleConfiguratorX.Labels.Add("Germany");
scaleConfiguratorX.Labels.Add("Norway");
scaleConfiguratorX.Labels.Add("Spain");
scaleConfiguratorX.Labels.Add("Belgium");
scaleConfiguratorX.Labels.Add("Greece");
scaleConfiguratorX.Labels.Add("Austria");
scaleConfiguratorX.Labels.Add("Sweden");
scaleConfiguratorX.Labels.Add("Finland");
scaleConfiguratorX.Labels.Add("Poland");
scaleConfiguratorX.Labels.Add("Denmark");

NBarSeries series1 = (NBarSeries)m_Chart.Series.Add(SeriesType.Bar);
series1.FillStyle = new NColorFillStyle(Color.Crimson);
series1.Name = "Product A";
series1.DataLabelStyle.Visible = false;
GenerateData(series1.Values, 12);

}

private void GenerateData(NDataSeries dataSeries, int count)
{
Random random = new Random();
for (int i = 0; i < count; i++)
{
dataSeries.Add(random.NextDouble() * 99 + 1);
}
}

Attachments
screenshot.PNG (48 views, 5.00 KB)
bob milanov
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)Supreme Being (152 reputation)

Group: Forum Members
Last Active: 6 Months Ago
Posts: 153, Visits: 11

Hi Inhyuk,

The remove overlap labels mode is not generally intended for public usage. It is used internally in some cases of the value timeline axis and relies on the label z order index. It can be useful with custom labels only as there is a way to assign z order index to labels:

  private void Form1_Load(object sender, EventArgs e)
  {
   NChart m_Chart = nChartControl1.Charts[0];
   m_Chart.BoundsMode = BoundsMode.Stretch;

   NStandardScaleConfigurator scaleConfiguratorX = (NStandardScaleConfigurator)m_Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator;
   //scaleConfiguratorX.MajorTickMode = MajorTickMode.CustomStep;

   scaleConfiguratorX.CustomLabelFitModes = new LabelFitMode[] { LabelFitMode.RemoveOverlap };

   scaleConfiguratorX.AutoLabels = false;

   string[] labels = new string[] {
            "France",
            "Italy",
            "Germany",
            "Norway",
            "Spain",
            "Belgium",
            "Greece",
            "Austria",
            "Sweden",
            "Finland",
            "Poland",
            "Denmark" };

   for (int i = 0; i < labels.Length; i++)
   {
    NCustomValueLabel valueLabel = new NCustomValueLabel();

    valueLabel.Text = labels[i];
    valueLabel.Value = i;
    valueLabel.Style.ZOrder = i % 2;

    scaleConfiguratorX.CustomLabels.Add(valueLabel);
   }  

   NBarSeries series1 = (NBarSeries)m_Chart.Series.Add(SeriesType.Bar);
   series1.FillStyle = new NColorFillStyle(Color.Crimson);
   series1.Name = "Product A";
   series1.DataLabelStyle.Visible = false;

   GenerateData(series1.Values, 12);
  }

  private void GenerateData(NDataSeriesDouble dataSeries, int count)
  {
   Random random = new Random();
   for (int i = 0; i < count; i++)
   {
    dataSeries.Add(random.NextDouble() * 99 + 1);
   }
  }

for example will remove overlapping adjacent labels. Again this mode is not intended for use in a categorical scale - generally it's intended to remove automatic labels that overlap custom ones.

Best regards,
Bob





Similar Topics


Reading This Topic