zedGraph Barchart Bars Overlapping Issue

时间:2015-09-08 04:09:29

标签: c# zedgraph

我正在使用zedGraph在C#中绘制BarCharts。当我尝试绘制大量数据时,我遇到与条宽相关的问题,例如超过5年的每日数据。酒吧变得越来越宽和重叠。有没有办法自动缩放条宽以适应窗格?

这是我正在尝试的代码:

        private void precipitationBHChart(ZedGraphControl zgc, DataTable dataTable) 
    {
        dataTable.Columns[0].ColumnName = "Date";
        dataTable.Columns[1].ColumnName = "Precipitation";

        GraphPane myPane = zgc.GraphPane;

        //// set opposite axes major tic and minor tic
        myPane.XAxis.MajorTic.IsOpposite = false;
        myPane.XAxis.MinorTic.IsOpposite = false;
        myPane.YAxisList[0].MajorTic.IsOpposite = false;
        myPane.YAxisList[0].MinorTic.IsOpposite = false;

        // set xAxis type to date
        myPane.XAxis.Type = AxisType.Date;

        // Disable zoom
        zgc.ZoomButtons = MouseButtons.None;
        zgc.ZoomButtons2 = MouseButtons.None;
        zgc.ZoomStepFraction = 0;

        // set xAxis scale min and max value
        object maxDate = dataTable.Compute("MAX(Date)", null);
        object minDate = dataTable.Compute("MIN(Date)", null);

        myPane.XAxis.Scale.Max = Convert.ToDateTime(maxDate).ToOADate();
        myPane.XAxis.Scale.Min = Convert.ToDateTime(minDate).ToOADate();

        // Make up some data points from the Sine function
        PointPairList list1 = new PointPairList();

        foreach (DataRow dr in dataTable.Rows)
        {
            list1.Add(Convert.ToDateTime(dr[0]).ToOADate(), Convert.ToDouble(dr[1]));
        }

        BarItem bar1 = myPane.AddBar("Precipitation", list1, Color.DarkGray);

        // Calculate the Axis Scale Ranges
        zgc.AxisChange();
    }

以下是示例图表: https://drive.google.com/file/d/0B8BnppTIW9YFczF4ZnlTLUJjOG8/view?usp=sharing

0 个答案:

没有答案