I have a chart in C# where I bind values to it. I have two different arrays with values and concat them to one chart. Now I wanted to display one part of the chart (with the values from the first array) in a different color. How to do this? drawing two charts causes errors so I wanted to do it this way. Here is a part of the code:
String[] x_axis = _temp_date1.Concat(_date).ToArray();
Double[] y_axis = _temp_data.Concat(_value).ToArray();
chart1.Series["Chart"].Points.DataBindXY(x_axis, y_axis);
chart1.Series["Chart"].ChartType = SeriesChartType.Spline;
chart1.Series["Chart"].Points[0].Color = System.Drawing.Color.Red;
chart1.Series["Chart"].Points[1].Color = System.Drawing.Color.Green;
The part with the Color doesn't work.
So lets say I have two arrays for the x values (date1 and date2) and two arrays for the y values (data1 and data2), Now I merge the date1 and date2 arrays and I merge the data1 and data2 arrays. I bind them to my graph. Now I would like to display the part of the graph in a different color where my values from the date1/data1 arrays come from. The array length can change because the data is read from a csv file.
Here is an example that shows both: Two separate
ChartAreas
in the sameChart
and twoSeries
in the sameChartArea
. Pick which you want:Here is the result:
Now if you simply want to change the color of the points after a certain number of points you could do it like this:
Note that you need to set the color of each point that shall have a different color from the default chart color!
In your
charts
control properties :Series
-->Member[n]
-->Color
-->Red
, and so onOR
Edit (According to the discussion in the comments, you can try something like):
Say we have an array of
doubles
, and we want to plot it each portion in a different color :