Profile Picture

How to set different colors for the points in one series

Posted By Xiaolong Zhu 13 Years Ago

How to set different colors for the points in one series

Author
Message
Xiaolong Zhu
Posted 13 Years Ago
View Quick Profile
Junior Member

Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 18, Visits: 1
 

Hi experts,

I want to create a chart with several point series. To show each series in the legend, i specified different fill styles for the series. Additionally, in each point series, i want to draw the points with different colors. So i also set various colors to the different points. But the result is the points take the series color not the point color. i copied my code here, is there anyone could give any hints? thanks in advance.

//create NPointSeries

public NPointSeries AddPointSeries(IEnumerable<Point> pts, Color seriesColor, string name)

{

NPointSeries series = (NPointSeries)_chart.Series.Add(SeriesType.Point);

series.UseXValues = true;

series.DataLabelStyle.Visible = false;

series.PointShape = PointShape.Ellipse;

series.Name = name;

series.FillStyle = new NColorFillStyle(seriesColor);

foreach(Point pt in pts)

{

NDataPoint dataPoint = new NDataPoint(pt.X, pt.Y);

series.AddDataPoint(dataPoint);

}

UpdatePointSeriesAppearence(series);

return series;

}

// set different colors to each point

private void UpdatePointSeriesAppearence(NPointSeries series)

{

for (int iPt = 0; iPt < series.GetDataPointCount(); iPt++)

{

NDataPoint dataPoint = series.ComposeDataPoint(iPt);

Color color = GetPtColor(iPt);

if (settings.SymbolType == SymbolStyle.None)

{

dataPoint[DataPointValue.StrokeStyle] = new NStrokeStyle(1, color);

dataPoint[DataPointValue.FillStyle] = new NColorFillStyle(Color.Transparent);

}

else

{

dataPoint[DataPointValue.StrokeStyle] = new NStrokeStyle(1, color);

dataPoint[DataPointValue.FillStyle] = new NColorFillStyle(color);

}

}

}

 


Nevron Support
Posted 13 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: 2 days ago @ 1:54 AM
Posts: 3,054, Visits: 4,009

Hi Xiaolong,

The problem is that you need to store the composed data point - for example:

   NChart chart = nChartControl1.Charts[0];

   NPointSeries point = new NPointSeries();

   point.Values.Add(10);
   point.Values.Add(20);
   point.Values.Add(30);

   chart.Series.Add(point);

   // using compose
   for (int i = 0; i < point.Values.Count; i++)
   {
    NDataPoint dataPoint = point.ComposeDataPoint(i);

    if (i % 2 == 0)
    {
     dataPoint[DataPointValue.FillStyle] = new NColorFillStyle(Color.Red);
    }
    else
    {
     dataPoint[DataPointValue.FillStyle] = new NColorFillStyle(Color.Green);
    }

// store the data point after you modify it

    point.StoreDataPoint(i, dataPoint);
   }

   nChartControl1.Refresh();

alternatively you can simply use the FillStyles/StrokeStyles collections:

   NChart chart = nChartControl1.Charts[0];

   NPointSeries point = new NPointSeries();

   point.Values.Add(10);
   point.Values.Add(20);
   point.Values.Add(30);

   chart.Series.Add(point);

   // using collections
   for (int i = 0; i < point.Values.Count; i++)
   {
    if (i % 2 == 0)
    {
     point.FillStyles[i] = new NColorFillStyle(Color.Red);
    }
    else
    {
     point.FillStyles[i] = new NColorFillStyle(Color.Green);
    }
   }

   nChartControl1.Refresh();

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

 



Best Regards,
Nevron Support Team



Xiaolong Zhu
Posted 13 Years Ago
View Quick Profile
Junior Member

Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)Junior Member (18 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 18, Visits: 1
Thanks, it works now.



Similar Topics


Reading This Topic