The code is follow,the chart is as the attachment. How can I set the thickness of the linechart to 10?
//定义数据源,根据其可方便设置series DataTable dt = new DataTable(); dt.Columns.Add("col1", typeof(int)); dt.Columns.Add("col2", typeof(int)); dt.Columns.Add("col3", typeof(int)); dt.Columns.Add("col4", typeof(string)); dt.Rows.Add(new object[] { 2, 14, 12, "H1" }); dt.Rows.Add(new Object[] { 0, 11, 10, "H2" }); dt.Rows.Add(new Object[] { 1, 9, 11, "H3" }); dt.Rows.Add(new Object[] { 0, 10, 11, "H4" }); dt.Rows.Add(new Object[] { 4, 12, 9, "H5" }); dt.Rows.Add(new Object[] { 1, 11, 10, "H6" }); dt.Rows.Add(new Object[] { 1, 8, 7, "H7" }); dt.Rows.Add(new Object[] { 5, 10, 10, "H8" });
//以下开始介绍生成Composite的完整步骤
//第一步:设置UltraChart1图表为组合图表Composite this.Chart1.ChartType = ChartType.Composite;
ThreeDEffect tdft = new ThreeDEffect(); tdft.Enabled = true;
Chart1.Effects.Effects.Add(tdft); StrokeEffect sdft = new StrokeEffect(); sdft.Enabled = true; Chart1.Effects.Effects.Add(sdft); //StrokeEffect s1 = new StrokeEffect(); //s1.StrokeColor = Color.Black; //// s1.StrokeOpacity = 100; //s1.StrokeWidth = 1; //Chart1.Effects.Effects.Add(s1); //第二步:创建一个图表区域ChartArea,并在UltraChart1图表组合中增加一个图表区域 ChartArea area = new ChartArea(); this.Chart1.CompositeChart.ChartAreas.Add(area);
//第三步:创建X轴,X2轴和Y轴,并添加到图表区域 //创建X轴,Composite的ColumnChart需要 AxisItem xAxisColumn = new AxisItem(); xAxisColumn.OrientationType = AxisNumber.X_Axis; xAxisColumn.DataType = AxisDataType.String; xAxisColumn.SetLabelAxisType = Infragistics.UltraChart.Core.Layers.SetLabelAxisType.GroupBySeries; xAxisColumn.Labels.ItemFormat = AxisItemLabelFormat.ItemLabel; xAxisColumn.Extent = 20; //创建Y轴,Composite的ColumnChart和LineChart都需要 AxisItem yAxis = new AxisItem(); yAxis.OrientationType = AxisNumber.Y_Axis; yAxis.DataType = AxisDataType.Numeric; yAxis.Labels.ItemFormat = AxisItemLabelFormat.DataValue; yAxis.RangeType = AxisRangeType.Custom; yAxis.RangeMin = 0; yAxis.RangeMax = 20; yAxis.Extent = 2; //创建X2轴, Composite的LineChart需要
AxisItem xAxisLine = new AxisItem(); xAxisLine.OrientationType = AxisNumber.X2_Axis; xAxisLine.DataType = AxisDataType.String; xAxisLine.SetLabelAxisType = Infragistics.UltraChart.Core.Layers.SetLabelAxisType.ContinuousData; xAxisLine.Labels.ItemFormat = AxisItemLabelFormat.ItemLabel; xAxisLine.Extent = 20; xAxisLine.Visible = false; //添加轴线到绘图区域 area.Axes.Add(xAxisColumn); area.Axes.Add(xAxisLine); area.Axes.Add(yAxis);
//第四步:创建若干曲线连续点实例,设置其取值 //生成ColumnChart所需的一个series NumericSeries seriesColumn = new NumericSeries(); //数据标签值 seriesColumn.Label = "A"; seriesColumn.Data.DataSource = dt; //轴线上显示的标签信息 seriesColumn.Data.LabelColumn = "col4"; //图表上要显示的值 seriesColumn.Data.ValueColumn = "col2"; seriesColumn.DataBind(); //生成ColumnChart所需的一个series NumericSeries seriesColumn2 = new NumericSeries(); //数据标签值 seriesColumn2.Label = "B"; seriesColumn2.Data.DataSource = dt; //轴线上显示的标签信息 seriesColumn2.Data.LabelColumn = "col4"; //图表上要显示的值 seriesColumn2.Data.ValueColumn = "col3"; seriesColumn2.DataBind(); //生成LineChart所需的一个series NumericSeries seriesLine = new NumericSeries(); for (int i = 0; i < 16; i++) { seriesLine.Points.Add(new NumericDataPoint(5, "12345", false)); PaintElement pe = new PaintElement(); pe.Fill = Color.Black; pe.Stroke = Color.Black; pe.StrokeWidth = 10; seriesLine.PEs.Add(pe); } this.Chart1.Series.Add(seriesLine); this.Chart1.Series.Add(seriesColumn); this.Chart1.Series.Add(seriesColumn2);
//第五步:创建图表样式(外观),并添加到图层集中 //ColumnChart的图表样式 ChartLayerAppearance ColumnLayer = new ChartLayerAppearance(); ColumnLayer.AxisX = xAxisColumn; ColumnLayer.AxisY = yAxis; ColumnLayer.ChartArea = area; //设置图表类型,ColumnChart条形图 ColumnLayer.ChartType = ChartType.ColumnChart;
ColumnLayer.Series.Add(seriesColumn); ColumnLayer.Series.Add(seriesColumn2); //LineChart的图表样式 ChartLayerAppearance LineLayer = new ChartLayerAppearance(); LineLayer.AxisX = xAxisLine; LineLayer.AxisY = yAxis; LineLayer.ChartArea = area; //设置图表类型,LineChart条形图 LineLayer.ChartType = ChartType.LineChart; LineChartAppearance my = new LineChartAppearance(); my.DrawStyle = LineDrawStyle.Solid; my.HighLightLines = true; my.MidPointAnchors = true; my.StartStyle = LineCapStyle.Triangle; my.Thickness = 10; LineLayer.ChartTypeAppearance = my; LineLayer.Series.Add(seriesLine); this.Chart1.CompositeChart.ChartLayers.Add(ColumnLayer); this.Chart1.CompositeChart.ChartLayers.Add(LineLayer);
Hi,
As you are using an additional chart stroke effect, it is overriding the line appearance settings. Try to set the StrokeEffect thickness property:
sdft.StrokeWidth = 10;
Let us if you have further questions.
I only want to bold the line not the border of the rectangle!
As the Effect overrides the Line appearance, if you want to preserve the effect and have different settings for the line layer, you should use the ChartDrawItem event. For example:
protected void Page_Load(object sender, EventArgs e)
{ ... this.Chart1.ChartDrawItem += new Infragistics.UltraChart.Shared.Events.ChartDrawItemEventHandler(Chart1_ChartDrawItem);}
void Chart1_ChartDrawItem(object sender, Infragistics.UltraChart.Shared.Events.ChartDrawItemEventArgs e){ Polyline p = e.Primitive as Polyline; if (p != null) { ((Infragistics.UltraChart.Core.Primitives.Primitive)(p)).PE.StrokeWidth = 10; }}
Thanks!
Thank you very much!