I have a columnline chart that has data points in the column and a goal in the line. The data points are all over months. I'd like to change the color of the column if it's lower than the goal line. I know how to change the color of the column based on a static value, but I'm not sure how to do it based on the line value.
Any help would be appreciated.
Thanks!
Try changing the event handler function to:
private void UltraChart1_ChartDrawItem(object sender, ChartDrawItemEventArgs e)
{
Box box = e.Primitive as Box;
if (box == null || e.HasData == false)
return;
}
double lineValue = (double)theData.Rows[box.Column]["Actual"];
NumericDataPoint dataPoint = box.DataPoint as NumericDataPoint;
if (dataPoint.Value < lineValue)
box.PE = new PaintElement(Color.Red);
Here is the code for the chart. "Actual. is used for the columns and "Goal" is used for the line.
Dim theData As DataTable = GetData()
If Not theData.Rows.Count = 0 Then Dim minActual As Double = theData.Compute("Min(Actual)", "") - 0.002 Dim maxActual As Double = theData.Compute("Max(Actual)", "") + 0.002 Me.UltraChart1.Axis.Y.RangeType = AxisRangeType.Custom Me.UltraChart1.Axis.Y2.RangeType = AxisRangeType.Custom Me.UltraChart1.Axis.Y.RangeMin = minActual Me.UltraChart1.Axis.Y2.RangeMin = minActual If maxActual < 1 Then Me.UltraChart1.Axis.Y.RangeMax = maxActual Me.UltraChart1.Axis.Y2.RangeMax = maxActual Else Me.UltraChart1.Axis.Y.RangeMax = 1 Me.UltraChart1.Axis.Y2.RangeMax = 1 End If End If
Me.UltraChart1.ColumnLineChart.ColumnData.DataSource = theData Me.UltraChart1.ColumnLineChart.ColumnData.SwapRowsAndColumns = True Me.UltraChart1.ColumnLineChart.ColumnData.IncludeColumn("Goal", False) Me.UltraChart1.ColumnLineChart.ColumnData.IncludeColumn("VtoGoal", False) Me.UltraChart1.ColumnLineChart.ColumnData.IncludeColumn("CostOfDefects", False) Me.UltraChart1.ColumnLineChart.ColumnData.IncludeColumn("DefectsPercentLines", False) Me.UltraChart1.ColumnLineChart.ColumnData.IncludeColumn("TotalDefects", False) Me.UltraChart1.ColumnLineChart.ColumnData.DataBind() Me.UltraChart1.ColumnLineChart.LineData.DataSource = theData Me.UltraChart1.ColumnLineChart.LineData.SwapRowsAndColumns = True Me.UltraChart1.ColumnLineChart.LineData.IncludeColumn("Actual", False) Me.UltraChart1.ColumnLineChart.LineData.IncludeColumn("VtoGoal", False) Me.UltraChart1.ColumnLineChart.LineData.IncludeColumn("CostOfDefects", False) Me.UltraChart1.ColumnLineChart.LineData.IncludeColumn("DefectsPercentLines", False) Me.UltraChart1.ColumnLineChart.LineData.IncludeColumn("TotalDefects", False) Me.UltraChart1.ColumnLineChart.LineData.DataBind()
It is static in my sample code. You need to find the correspoding line value. If you send me you data binding code, I'll try find the correct values.
Thank you for your reply.
However, unless I'm reading that wrong, it is changing the color of the column based on a static value.
if (dataPoint.Value < 20) // compare with the line value
My line values are not static, so I would need them to be based on whatever the line value is for that month.
Any ideas, or am I reading your code wrong?
One thing you can do is handling the ChartDrawItem event:
…
this.UltraChart1.ChartDrawItem += new ChartDrawItemEventHandler(UltraChart1_ChartDrawItem);
You can use box.Row and box.Column to find the corresponding line value from your data source.