/// <summary> /// Name:设置XY轴 /// Author:by boxuming 2019-04-23 14:35 /// </summary> /// <param name="chart">图表对象</param> /// <param name="xTitle">X轴标题</param> /// <param name="yTitle">Y轴标题</param> /// <param name="align">坐标轴标题对齐方式</param> /// <param name="foreColor">坐标轴字体颜色</param> /// <param name="lineColor">坐标轴颜色</param> /// <param name="arrowStyle">坐标轴箭头样式</param> /// <param name="xInterval">X轴的间距</param> /// <param name="yInterval">Y轴的间距</param> public static void SetXY(Chart chart, string xTitle, string yTitle, StringAlignment align, Color foreColor, Color lineColor, AxisArrowStyle arrowStyle, double xInterval, double yInterval, double y2Interval) { chart.ChartAreas[0].AxisX.Title = xTitle; chart.ChartAreas[0].AxisY.Title = yTitle; chart.ChartAreas[0].AxisX.TitleAlignment = align; chart.ChartAreas[0].AxisY.TitleAlignment = align; chart.ChartAreas[0].AxisX.TitleForeColor = foreColor; chart.ChartAreas[0].AxisY.TitleForeColor = foreColor; chart.ChartAreas[0].AxisX.LabelStyle = new LabelStyle() { ForeColor = foreColor }; chart.ChartAreas[0].AxisY.LabelStyle = new LabelStyle() { ForeColor = foreColor }; chart.ChartAreas[0].AxisX.LineColor = lineColor; chart.ChartAreas[0].AxisY.LineColor = lineColor; chart.ChartAreas[0].AxisX.ArrowStyle = arrowStyle; chart.ChartAreas[0].AxisY.ArrowStyle = arrowStyle; chart.ChartAreas[0].AxisX.Interval = xInterval; chart.ChartAreas[0].AxisY.Interval = yInterval; if (y2Interval > 0) { chart.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True; chart.ChartAreas[0].AxisY2.TitleAlignment = align; chart.ChartAreas[0].AxisY2.TitleForeColor = foreColor; chart.ChartAreas[0].AxisY2.LabelStyle = new LabelStyle() { ForeColor = foreColor }; chart.ChartAreas[0].AxisY2.LineColor = lineColor; chart.ChartAreas[0].AxisY2.ArrowStyle = arrowStyle; chart.ChartAreas[0].AxisY2.Interval = yInterval + 10; } //return chart; }
public static void Initialize( this Chart chart, string title, string legendsTitle, Font font, string axisXTitle = "X", string axisYTitle = "Y", string areasName = "area", Color color = default, AxisArrowStyle axisArrowStyle = AxisArrowStyle.Triangle) { if (color.IsEmpty) { color = Color.Black; } chart.Titles.Add(title).Font = font; chart.Legends.Add(legendsTitle); chart.Legends[legendsTitle].Title = legendsTitle; chart.Legends[legendsTitle].TitleFont = font; chart.ChartAreas.Add(areasName); chart.ChartAreas[areasName].AxisX.Title = axisXTitle; chart.ChartAreas[areasName].AxisX.ArrowStyle = axisArrowStyle; chart.ChartAreas[areasName].AxisX.TitleFont = font; chart.ChartAreas[areasName].AxisX.TitleForeColor = color; chart.ChartAreas[areasName].AxisX2.Title = axisXTitle; chart.ChartAreas[areasName].AxisX2.ArrowStyle = axisArrowStyle; chart.ChartAreas[areasName].AxisX2.TitleFont = font; chart.ChartAreas[areasName].AxisX2.TitleForeColor = color; chart.ChartAreas[areasName].AxisY.Title = axisYTitle; chart.ChartAreas[areasName].AxisY.ArrowStyle = axisArrowStyle; chart.ChartAreas[areasName].AxisY.TitleFont = font; chart.ChartAreas[areasName].AxisY.TitleForeColor = color; chart.ChartAreas[areasName].AxisY2.Title = axisYTitle; chart.ChartAreas[areasName].AxisY2.ArrowStyle = axisArrowStyle; chart.ChartAreas[areasName].AxisY2.TitleFont = font; chart.ChartAreas[areasName].AxisY2.TitleForeColor = color; }
/// <summary> /// Name:设置XY轴 /// </summary> /// <param name="chart">图表对象</param> /// <param name="xTitle">X轴标题</param> /// <param name="yTitle">Y轴标题</param> /// <param name="align">坐标轴标题对齐方式</param> /// <param name="foreColor">坐标轴字体颜色</param> /// <param name="lineColor">坐标轴颜色</param> /// <param name="arrowStyle">坐标轴箭头样式</param> /// <param name="xInterval">X轴的间距</param> /// <param name="yInterval">Y轴的间距</param> public static void SetXY(Chart chart, string xTitle, string yTitle, StringAlignment align, Color foreColor, Color lineColor, AxisArrowStyle arrowStyle, double xInterval, double yInterval) { chart.ChartAreas[0].AxisX.Title = xTitle; chart.ChartAreas[0].AxisY.Title = yTitle; chart.ChartAreas[0].AxisX.TitleAlignment = align; chart.ChartAreas[0].AxisY.TitleAlignment = align; chart.ChartAreas[0].AxisX.TitleForeColor = foreColor; chart.ChartAreas[0].AxisY.TitleForeColor = foreColor; chart.ChartAreas[0].AxisX.LabelStyle = new LabelStyle() { ForeColor = foreColor }; chart.ChartAreas[0].AxisY.LabelStyle = new LabelStyle() { ForeColor = foreColor }; chart.ChartAreas[0].AxisX.LineColor = lineColor; chart.ChartAreas[0].AxisY.LineColor = lineColor; chart.ChartAreas[0].AxisX.ArrowStyle = arrowStyle; chart.ChartAreas[0].AxisY.ArrowStyle = arrowStyle; chart.ChartAreas[0].AxisX.Interval = xInterval; chart.ChartAreas[0].AxisY.Interval = yInterval; }