Profile Picture

Can't change grid color in chart

Posted By Syrhey Karol' Last Year
Author
Message
Syrhey Karol'
Posted Last Year
View Quick Profile
Forum Member

Forum Member (27 reputation)Forum Member (27 reputation)Forum Member (27 reputation)Forum Member (27 reputation)Forum Member (27 reputation)Forum Member (27 reputation)Forum Member (27 reputation)Forum Member (27 reputation)Forum Member (27 reputation)

Group: Forum Members
Last Active: Last Year
Posts: 21, Visits: 74
Hi
I created a simle chart, make grid visible on X axis in Red color.
Then I added a button and if I click on the button I'd like to change X Axis Grid color to Yellow. 
But it doesn't work.
Could you help me, please? 

Designer source code:
namespace WinFormsApp1
{
  partial class Form1
  {
   /// <summary>
   /// Required designer variable.
   /// </summary>
   private System.ComponentModel.IContainer components = null;

   /// <summary>
   /// Clean up any resources being used.
   /// </summary>
   /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
   protected override void Dispose(bool disposing)
   {
    if (disposing && (components != null))
    {
      components.Dispose();
    }
    base.Dispose(disposing);
   }

   #region Windows Form Designer generated code

   /// <summary>
   /// Required method for Designer support - do not modify
   /// the contents of this method with the code editor.
   /// </summary>
   private void InitializeComponent()
   {
    this.button1 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    //
    // button1
    //
    this.button1.Location = new System.Drawing.Point(12, 12);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(75, 23);
    this.button1.TabIndex = 0;
    this.button1.Text = "button1";
    this.button1.UseVisualStyleBackColor = true;
    this.button1.Click += new System.EventHandler(this.button1_Click);
    //
    // Form1
    //
    this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(800, 450);
    this.Controls.Add(this.button1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false);

   }

   #endregion
  
   private Button button1;
  }
}


CS file source code:
using Nevron.Chart;
using Nevron.GraphicsCore;
using System.Drawing;

namespace WinFormsApp1
{
  public partial class Form1 : Form
  {
   public Nevron.Chart.WinForm.NChartControl nChartControl1;
   public Form1()
   {
    InitializeComponent();

    this.nChartControl1 = new Nevron.Chart.WinForm.NChartControl();
    //
    // _nChartCtrl
    //
    this.nChartControl1.AllowDrop = true;
    this.nChartControl1.AutoRefresh = false;
    this.nChartControl1.BackColor = System.Drawing.SystemColors.Control;
    this.nChartControl1.Dock = System.Windows.Forms.DockStyle.Fill;
    this.nChartControl1.InputKeys = new System.Windows.Forms.Keys[0];
    this.nChartControl1.Location = new System.Drawing.Point(0, 0);
    this.nChartControl1.Name = "_nChartCtrl";
    this.nChartControl1.Size = new System.Drawing.Size(743, 560);
    this.nChartControl1.TabIndex = 0;
    this.Controls.Add(this.nChartControl1);


    // set a chart title
    NLabel title = nChartControl1.Labels.AddHeader("2D Line Chart");
    title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic);
    title.ContentAlignment = ContentAlignment.BottomCenter;
    title.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage));

    // no legend
    nChartControl1.Legends.Clear();

    // configure the chart
    NChart chart = nChartControl1.Charts[0];

    // X Axis
    chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator.MajorGridStyle.SetShowAtWall(ChartWallType.Back, true);
    chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator.MajorGridStyle.LineStyle.Color = Color.Red;

    NLineSeries line = (NLineSeries)chart.Series.Add(SeriesType.Line);
    line.Name = "Line Series";
    line.InflateMargins = true;
    line.DataLabelStyle.Format = "<value>";
    line.MarkerStyle.Visible = true;
    line.MarkerStyle.PointShape = PointShape.Cylinder;
    line.MarkerStyle.Width = new NLength(1.5f, NRelativeUnit.ParentPercentage);
    line.MarkerStyle.Height = new NLength(1.5f, NRelativeUnit.ParentPercentage);
    line.ShadowStyle.Type = ShadowType.GaussianBlur;
    line.ShadowStyle.Offset = new NPointL(3, 3);
    line.ShadowStyle.FadeLength = new NLength(5);
    line.ShadowStyle.Color = Color.FromArgb(55, 0, 0, 0);
    line.Values.FillRandom(new Random(), 8);
   }

   private void button1_Click(object sender, EventArgs e)
   {
    nChartControl1.Charts[0].Axis(StandardAxis.PrimaryX).ScaleConfigurator.MajorGridStyle.LineStyle.Color = Color.Yellow;

    nChartControl1.Invalidate(true);
    nChartControl1.Charts[0].Refresh();
   }
  }
}


Tags
Nevron Support
This post has been flagged as an answer
Posted Last Year
View Quick Profile
Supreme Being

Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)

Group: Forum Members
Last Active: Last Year
Posts: 3,039, Visits: 3,746
Hi Syrthey,

It looks like there is a small issue with the scale configurator - it does not mark the scale for update so you need to force the update:

This code worked Ok:
  private void button1_Click(object sender, EventArgs e)
   {
    nChartControl1.Charts[0].Axis(StandardAxis.PrimaryX).ScaleConfigurator.MajorGridStyle.LineStyle.Color = Color.Yellow;
    nChartControl1.Charts[0].Axis(StandardAxis.PrimaryX).InvalidateScale();

    nChartControl1.Refresh();
   }

We'll be looking in detail in the problem and the fix will appear in the next major release of the control. We hope this helps - let us know if you have any questions or meet any problems.

Best Regards,
Nevron Support Team



Syrhey Karol'
Posted Last Year
View Quick Profile
Forum Member

Forum Member (27 reputation)Forum Member (27 reputation)Forum Member (27 reputation)Forum Member (27 reputation)Forum Member (27 reputation)Forum Member (27 reputation)Forum Member (27 reputation)Forum Member (27 reputation)Forum Member (27 reputation)

Group: Forum Members
Last Active: Last Year
Posts: 21, Visits: 74
Hi!
Thank you a lot for workaround!
It works



Similar Topics


Reading This Topic