user3271698
user3271698

Reputation: 155

Change chart control style

In my application i have chart control that received real time data and update my graph via timer:

Series seriesTraffic = new Series();
seriesTraffic.Color = Color.Red;
seriesTraffic.ChartType = SeriesChartType.Spline;
seriesTraffic.BorderWidth = 2;
chart1.Series.Add(seriesTraffic);
chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.White;
chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.White;
chart1.ChartAreas[0].AxisX.LabelStyle.Enabled = false;
chart1.ChartAreas[0].AxisY.LabelStyle.Enabled = false;
chart1.ChartAreas[0].AxisX.IsStartedFromZero = true;
chart1.ChartAreas[0].AxisX.IntervalOffsetType = DateTimeIntervalType.Number;

private void chartTimer_Tick(object sender, EventArgs e)
{
    if (seriesTraffic.Points.Count() > 100)
        seriesTraffic.Points.RemoveAt(0);
    seriesTraffic.Points.Add(wf.BitsPerSecond * 0.000001);
    chart1.ResetAutoValues();
}

enter image description here

What i want to do is 2 thing:

  1. change the white background color - i try to change several properties but it does not changed
  2. remove Series1 and Series2 so my graph will be in full size inside the rectangle

Upvotes: 0

Views: 3380

Answers (1)

mmathis
mmathis

Reputation: 1610

In the designer, with the Chart selected, there is a property for Series. Open up this property, and you should see some series in there (Series1, maybe more). Remove them. In your code above, you also need to add a line

Series seriesTraffic = new Series();
seriesTraffic.IsVisibleInLegend = false; // add this line
seriesTraffic.Color = Color.Red;

Alternatively, you can just hide the legend. There is a property in the designer for Legends, and there should be a default one in there. Change it's Visible or Enabled property to false.

As mentioned, the BackColor property can be changed to change the background from white to another color.

You may also want to download the chart samples pack from MSDN: http://archive.msdn.microsoft.com/mschart . It has a lot of examples and code snippets, and can show you some of the things you can do with these charts

Upvotes: 1

Related Questions