Hello
I created a columnLine chart
and bound it to a datatable with two columns one for the column series and the other for the line series
I used the following code to draw the line serie in a different color
private void Chart_ChartDrawItem(object sender, ChartDrawItemEventArgs e) { if (e.Primitive is Polyline ) { e.Primitive.PE.Fill = Color.Firebrick; } }
and I used the following code to bind the data
chart.ColumnLineChart.ColumnData.DataSource = datatable; chart.ColumnLineChart.ColumnData.IncludeColumn("line", false); chart.ColumnLineChart.ColumnData.SwapRowsAndColumns = true; chart.ColumnLineChart.ColumnData.DataBind(); chart.ColumnLineChart.LineData.DataSource = datatable; chart.ColumnLineChart.LineData.IncludeColumn("column", false); chart.ColumnLineChart.LineData.SwapRowsAndColumns = true; chart.ColumnLineChart.LineData.DataBind();
My problem is that now I now only have the column series in my legend.
hmm, i wonder why that is. does this work for you?
DataTable table1 = new DataTable(); table1.Columns.Add("rowlabel", typeof(string)); table1.Columns.Add("coldata_a", typeof(double)); table1.Columns.Add("coldata_b", typeof(double)); table1.Columns.Add("coldata_c", typeof(double)); table1.Rows.Add(new object[] { "col a", 1, 1, 1 }); table1.Rows.Add(new object[] { "col b", 2, 2, 2 }); table1.Rows.Add(new object[] { "col c", 3, 3, 3 }); DataTable table2 = new DataTable(); table2.Columns.Add("rowlabel", typeof(string)); table2.Columns.Add("linedata_a", typeof(double)); table2.Columns.Add("linedata_b", typeof(double)); table2.Columns.Add("linedata_c", typeof(double)); table2.Rows.Add(new object[] { "line a", 1, 1, 1 }); table2.Rows.Add(new object[] { "line b", 2, 2, 2 }); table2.Rows.Add(new object[] { "line c", 3, 3, 3 }); UltraChart1.ChartType = ChartType.ColumnLineChart; UltraChart1.ColumnLineChart.ColumnData.DataSource = table1; UltraChart1.ColumnLineChart.ColumnData.DataBind(); UltraChart1.ColumnLineChart.LineData.DataSource = table2; UltraChart1.ColumnLineChart.LineData.DataBind(); UltraChart1.Legend.Visible = true; UltraChart1.Legend.DataAssociation = ChartTypeData.SplitData;
I am using a ColumnLine Chart as well,
I set the datasource for the column data to one DataTable, and set the datasource for the line data to another DataTable.
When I use
UltraChart1.Legend.DataAssociation = ChartTypeData.SplitData;
I get two legend 'boxes' both with the lineChart item in them!
What am I doing wrong?
try this:
this.ultraChart1.Legend.DataAssociation = ChartTypeData.SplitData;
that will make your legend show the line data as well as the column data. but the legend icon for the line will be the wrong color, because you recolored the line in the chart.
in order to get this to work properly, i had to implement a FillSceneGraph event handler. here's the complete code:
private void Form1_Load(object sender, EventArgs e) { this.ultraChart1.ChartType = ChartType.ColumnLineChart; DataTable table = new DataTable(); table.Columns.Add("line", typeof(double)); table.Columns.Add("column", typeof(double)); table.Rows.Add(new object[] { 2.0, 3.0 }); table.Rows.Add(new object[] { 1.0, 1.0 }); table.Rows.Add(new object[] { 3.0, 2.0 }); this.ultraChart1.ColumnLineChart.ColumnData.DataSource = table; this.ultraChart1.ColumnLineChart.ColumnData.IncludeColumn("line", false); this.ultraChart1.ColumnLineChart.ColumnData.DataBind(); this.ultraChart1.ColumnLineChart.LineData.DataSource = table; this.ultraChart1.ColumnLineChart.LineData.SwapRowsAndColumns = true; this.ultraChart1.ColumnLineChart.LineData.IncludeColumn("column", false); this.ultraChart1.ColumnLineChart.LineData.DataBind(); this.ultraChart1.Legend.DataAssociation = ChartTypeData.SplitData; this.ultraChart1.Legend.Visible = true; } private void ultraChart1_ChartDrawItem(object sender, ChartDrawItemEventArgs e) { if (e.Primitive is Polyline) { e.Primitive.PE = new PaintElement(Color.Firebrick); } } private void ultraChart1_FillSceneGraph(object sender, FillSceneGraphEventArgs e) { for (int current = 0; current < e.SceneGraph.Count; current++) { Primitive currentPrim = e.SceneGraph[current]; bool legendBox = currentPrim is Box && currentPrim.Path != null && currentPrim.Path.Contains("Legend") && currentPrim.Row == 0; if (legendBox && current < e.SceneGraph.Count - 1) { Text nextLabel = e.SceneGraph[current + 1] as Text; if (nextLabel != null && nextLabel.GetTextString() == "line") { currentPrim.PE = new PaintElement(Color.Firebrick); } } } }