/// <summary> /// 条形图数据处理 /// </summary> /// <param name="chartTitle">标题</param> /// <param name="chartAxisData">坐标轴数据</param> /// <param name="seriesData">图表数据</param> /// <param name="lengendData">图例数据</param> /// <param name="chartGrid">直角坐标系内绘图网格</param> /// <param name="isShowX">X轴是否显示</param> /// <param name="isShowY">Y轴是否显示</param> /// <param name="isShowLengend">是否开启图例</param> /// <param name="chartSubTitle">副标题文本,默认值:'','\n'指定换行</param> /// <param name="isCalculable">是否启用拖拽重计算特性,默认关闭</param> /// <param name="isShowY1AxisTick">是否显示Y轴坐标轴小标记</param> /// <param name="isShowY1AxisLine">是否显示坐标轴线</param> /// <param name="dateTimeFormat"></param> /// <returns>图表所有数据</returns> public static string ChartTiaoBarDataProcess(string chartTitle, List <object> chartAxisData, IEnumerable <ChartRightangleSeries> seriesData, List <string> lengendData, ChartGrid chartGrid, bool isShowX = false, bool isShowY = true, bool isShowLengend = false, string chartSubTitle = null, bool isCalculable = false, bool isShowY1AxisTick = false, bool isShowY1AxisLine = false, string dateTimeFormat = "yyyy-MM-dd") { //标题 var title = new ChartTitle() { text = chartTitle, subtext = chartSubTitle }; //提示框 var chartTooltip = new ChartTooltip() { trigger = "axis" }; //图例 var chartLegend = new ChartLegend() { show = isShowLengend, data = lengendData }; //X坐标轴 var chartXAxis = new List <ChartAxis>() { new ChartAxis { type = "value", show = isShowX, boundaryGap = new List <object>() { 0, 0 } } }; //Y坐标轴 var chartYAxis = new List <ChartAxis>() { new ChartAxis() { type = "category", axisTick = new AxisTick() { show = isShowY1AxisTick }, axisLine = new AxisLine() { show = isShowY1AxisLine }, show = isShowY, data = chartAxisData } }; //数据 var chartRightangleSeries = new List <ChartRightangleSeries>(); chartRightangleSeries.AddRange(seriesData); var seriesDatas = chartRightangleSeries.Count > 0 ? chartRightangleSeries : (object)"-"; var jsonData = new { title, tooltip = chartTooltip, calculable = isCalculable, legend = chartLegend, grid = chartGrid, xAxis = chartXAxis, yAxis = chartYAxis, series = seriesDatas }; return(jsonData.ToJson(dateTimeFormat)); }
/// <summary> /// 多维条形图数据处理 /// </summary> /// <param name="chartTitle">标题</param> /// <param name="chartAxisData">坐标轴数据</param> /// <param name="seriesData">图表数据</param> /// <param name="chartLegend">图例</param> /// <param name="chartGrid">直角坐标系内绘图网格</param> /// <param name="chartSubTitle">副标题文本,默认值:'','\n'指定换行</param> /// <param name="isCalculable">是否启用拖拽重计算特性,默认关闭</param> /// <param name="dateTimeFormat"></param> /// <returns>图表所有数据</returns> public static string ChartDuoWeiTiaoBarDataProcess(string chartTitle, List <object> chartAxisData, IEnumerable <ChartRightangleSeries> seriesData, ChartLegend chartLegend, ChartGrid chartGrid, string chartSubTitle = null, bool isCalculable = false, string dateTimeFormat = "yyyy-MM-dd") { //标题 var title = new ChartTitle() { text = chartTitle, subtext = chartSubTitle }; //提示框 var chartTooltip = new ChartTooltip() { trigger = "axis", axisPointer = new AxisPointer()// 坐标轴指示器,坐标轴触发有效 { type = "shadow" }, formatter = "{b}<br/>{a0}:{c0}<br/>{a2}:{c2}<br/>{a4}:{c4}" }; //X坐标轴 var chartXAxis = new List <ChartAxis>() { new ChartAxis { type = "value", position = "top", splitLine = new SplitLine() { show = false }, axisLabel = new AxisLabel() { show = false } } }; //Y坐标轴 var chartYAxis = new List <ChartAxis>() { new ChartAxis() { type = "category", splitLine = new SplitLine() { show = false }, data = chartAxisData } }; //数据 var chartRightangleSeries = new List <ChartRightangleSeries>(); chartRightangleSeries.AddRange(seriesData); var seriesDatas = chartRightangleSeries.Count > 0 ? chartRightangleSeries : (object)"-"; var jsonData = new { title, tooltip = chartTooltip, legend = chartLegend, calculable = isCalculable, grid = chartGrid, xAxis = chartXAxis, yAxis = chartYAxis, series = seriesDatas }; return(jsonData.ToJson(dateTimeFormat)); }
/// <summary> /// 添加统计图 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void addMatic_Click(object sender, RoutedEventArgs e) { if (myChartCtrl1 != null) { myChartCtrl1.m_chart = null; myChartCtrl1.m_dataS = null; myChartCtrl1.Show(); } clearChart(); this.iMSMap1.OperType = ZDIMS.Util.IMSOperType.None; for (int m = 0; m < pntList.Count; m++) { Chart chart = new Chart(); chart.BorderThickness = new Thickness(0); //去掉边框 chart.Background = new SolidColorBrush(Colors.Transparent); //设置背景色透明 //去掉x轴线 Axis xaxis = new Axis(); xaxis.Enabled = false; ChartGrid xgrid = new ChartGrid(); //xgrid.Enabled = false; xaxis.Grids.Add(xgrid); chart.AxesX.Add(xaxis); //去掉y轴线 Axis yaxis = new Axis(); //yaxis.Enabled = false; ChartGrid ygrid = new ChartGrid(); ygrid.Enabled = false; yaxis.Grids.Add(ygrid); chart.AxesY.Add(yaxis); //统计数据设置 dataS = new DataSeries(); dataS.RenderAs = RenderAs.Column;//设置默认统计图类型为柱状图 DataPoint point; for (int i = 0; i < list.Count; i++) { point = new DataPoint(); point.YValue = list[i].YValue; point.AxisXLabel = list[i].XLabel; dataS.DataPoints.Add(point); } chart.Width = 200; chart.Height = 150; chart.Opacity = 1.00; Title title = new Title(); title.Text = pntList[m].PlaceName; chart.Titles.Add(title); //统计图标题 chart.Series.Add(dataS); dataS.LabelEnabled = true; //显示标签 chart.AnimationEnabled = true; chart.AnimatedUpdate = true; dataS.LabelStyle = LabelStyles.OutSide; //设置标签显示位置 chart.MouseLeftButtonDown += new MouseButtonEventHandler(chart_MouseLeftButtonDown); //鼠标左键按下事件监听 IMSMark mark = new IMSMark(chart); mark.CoordinateType = CoordinateType.Logic; mark.X = pntList[m].X; mark.Y = pntList[m].Y; mark.EnableRevisedPos = true; mark.EnableAnimation = false; mark.EnableDrag = false; this.markLayer1.AddMark(mark); } this.iMSMap1.SetInfoText("选择统计图,进行样式设置;右键菜单“取消选择状态”,取消选择", Colors.Black); MenuItem item = new MenuItem(); item.Header = "取消选择状态"; this.iMSMap1.ContextMenu.Items.Add(item); item.Click += new RoutedEventHandler(item_Click); }