Profile Picture

problems with NPallette

Posted By Hans Henrik Friis Pedersen... 9 Years Ago
Author
Message
Hans Henrik Friis Pedersen...
Problem 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: 8 Years Ago
Posts: 28, Visits: 136
Hi,

I'm using the code below to make a smooth pallette indicating the colors on the poinseries...

1) How do I locate the legend to the far right so  isn't located on top of the chart, hiding the chart below the legend??
2) How do I control the formating of the text inside the legend? also, the number of digits after the punctuation mark (for instance, 100,0 instead of 99.99)?
3) How do i control it so that only one column of numbers is shown in the legend?



private void Form1_Load(object sender, EventArgs e)
        {
            NChart chart = (NChart)(nChartControl1.Charts[0]);
            chart.Series.Clear();
 
            NPointSeries point1 = (NPointSeries)chart.Series.Add(SeriesType.Point);
                                     point1.Name = "Point 1";
            point1.PointShape = PointShape.Bar;
            point1.Size = new NLength(15, NGraphicsUnit.Point);
            point1.FillStyle = new NColorFillStyle(Color.Red);
            point1.BorderStyle.Color = Color.Pink;
            point1.DataLabelStyle.Visible = false;
            point1.UseXValues = true;
            point1.InflateMargins = true;
 
            NLegend legend = new NLegend();
            legend.Header.Text = "Agubsa!!";
            legend.Mode = LegendMode.Manual;
            legend.Data.ExpandMode = LegendExpandMode.VertWrap;
            legend.DockMode = PanelDockMode.Right;
            legend.SetPredefinedLegendStyle(PredefinedLegendStyle.Bottom);
            legend.Margins = new NMarginsL(20, 20, 20, 20);
            //chart.ChildPanels.Add(legend);
            nChartControl1.Panels.Add(legend);
 
            NPalette palette = new NPalette();
 
            int i = 0;
            for (i = 0; i <= 10; i++)
            {
                palette.Add(i*9.99,CoolColorCode(i*9.99));
            }
 
            palette.Mode = PaletteMode.Custom;
            palette.SmoothPalette = true;
 
            NLegendPaletteCellData m_PaletteCellData;
            m_PaletteCellData = new NLegendPaletteCellData(palette, new NRange1DD(0, 100));
 
            legend.Data.Items.Add(m_PaletteCellData);
 
            i = 0;
            for (i = 0; i < 10; i++)
            {
                point1.Values.Add(i);
                point1.XValues.Add(i * 10.1);
                point1.FillStyles[i] = new NColorFillStyle(CoolColorCode(i*10.1));
            }
            nChartControl1.Refresh();
 
        }
 
 
        private Color CoolColorCode(double ColorValue)
        {
            ColorValue = 100 - ColorValue;
 
            if (ColorValue < 0)
                ColorValue = 0;
            else if (ColorValue > 100)
                ColorValue = 100;
            else if (double.IsNaN(ColorValue))
                ColorValue = 0;
 
            if (ColorValue < 25)
                return Color.FromArgb(255, Convert.ToInt16(ColorValue / 25 * 255), 0);
            else if (ColorValue < 50)
                return Color.FromArgb(Convert.ToInt16(255 - ((ColorValue - 25) / 25 * 255)), 255, 0);
            else if (ColorValue < 75)
                return Color.FromArgb(0, 255, Convert.ToInt16((ColorValue - 50) / 25 * 255));
            else
                return Color.FromArgb(0, Convert.ToInt16(255 - Math.Round((ColorValue - 75) / 25 * 255)), 255);
        }




Attachments
Untitled.png (288 views, 15.00 KB)
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 Hans,

1) How do I locate the legend to the far right so  isn't located on top of the chart, hiding the chart below the legend?
The best way to do it is to use panel docking (see the code below). You can also change the Location / ContentAlignement of the legend in order to position it on the right - you can take a look at the following example:
All Examples \ Panels \ Legend

The following code shows how to create an automatic dock layout:
nChartControl1.Panels.Clear();
NLabel label = new NLabel("Header");
label.Margins = new NMarginsL(10);
label.DockMode = PanelDockMode.Top;
nChartControl1.Panels.Add(label);
NLegend legend = new NLegend();
legend.Margins = new NMarginsL(10);
nChartControl1.Panels.Add(legend);
legend.DockMode = PanelDockMode.Right;
NCartesianChart chart = new NCartesianChart();
chart.Margins = new NMarginsL(10);
nChartControl1.Panels.Add(chart);
chart.DisplayOnLegend = legend;
NBarSeries bar = new NBarSeries();
bar.Values.Add(10);
bar.Values.Add(20);
bar.Values.Add(30);
chart.Series.Add(bar);
bar.Legend.Mode = SeriesLegendMode.DataPoints;
bar.Legend.Format = "<value>";
bar.Values.ValueFormatter = new NNumericValueFormatter(".0");
chart.BoundsMode = BoundsMode.Stretch;
chart.DockMode = PanelDockMode.Fill;

2) How do I control the formatting of the text inside the legend? also, the number of digits after the punctuation mark (for instance, 100,0 instead of 99.99)?
You need to modify the scale value formatting:

NNumericScaleConfigurator paletteScale = paletteCellData.PaletteScaleConfigurator as NNumericScaleConfigurator;
paletteScale.LabelValueFormatter = new NNumericValueFormatter(".0");

3) How do i control it so that only one column of numbers is shown in the legend?

Probably this is related to staggered labels - to turn this feature off you can use:
paletteScale.LabelFitModes = new LabelFitMode[] { LabelFitMode.AutoScale };
You can also post a screenshot to illustrate the problem.

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