DunDas对应不同坐标系显示双y轴

来源:互联网 发布:node.js restful 框架 编辑:程序博客网 时间:2024/05/15 12:04

其实很简单(但对于CirCular Chart无效),就一句话: webchart.Series["bb"].YAxisType = AxisType.Secondary;

 /// <summary>
    /// 双y轴实现
    /// </summary>
    /// <returns></returns>
    public string GetImgFile()
    {
        ArrayList arrdate = new ArrayList();
        ArrayList arrvalue = new ArrayList();
        ArrayList arrvalues = new ArrayList();
        SetChartStyle("aaa", true);
        webchart.Series.Add("aa");
        webchart.Series.Add("bb");
        webchart.ChartAreas.Add("aa");
        webchart.ImageType = ChartImageType.Png;
        webchart.Width = 650;
        webchart.Height = 450;
        Random r = new Random(10);
        DateTime dt = System.DateTime.Now;
        for (int i = 0; i < 10; i++)
        {
            dt = dt.AddDays(1);
            arrdate.Add(dt.ToShortDateString());
            arrvalue.Add(i);
            arrvalues.Add(i + r.Next());
        }
        webchart.Series["aa"].Type = SeriesChartType.Column;
        webchart.ChartAreas["aa"].AxisX.MajorGrid.LineColor = Color.Silver;
        webchart.ChartAreas["aa"].AxisX.LineColor = Color.Silver;
        webchart.ChartAreas["aa"].AxisX.MajorTickMark.Size = 1;
        webchart.ChartAreas["aa"].AxisX.MajorGrid.Enabled = true;
        webchart.ChartAreas["aa"].AxisY.Enabled = AxisEnabled.True;
        webchart.ChartAreas["aa"].AxisY.MajorGrid.LineColor = Color.Silver;
        webchart.ChartAreas["aa"].AxisY.MajorGrid.Enabled = true;
        webchart.ChartAreas["aa"].AxisY.LineColor = Color.Silver;
        webchart.ChartAreas["aa"].AxisY.Title = "aa";
        webchart.ChartAreas["aa"].AxisY.MajorTickMark.Size = 0;
        webchart.ChartAreas["aa"].AxisY2.Enabled = AxisEnabled.True;
        webchart.ChartAreas["aa"].AxisY2.MajorGrid.LineColor = Color.Silver;
        webchart.ChartAreas["aa"].AxisY2.MajorGrid.Enabled = true;
        webchart.ChartAreas["aa"].AxisY2.LineColor = Color.Silver;
        webchart.ChartAreas["aa"].AxisY2.Title = "bb";
        webchart.ChartAreas["aa"].AxisY2.MajorTickMark.Size = 0;
        webchart.Series["aa"].Points.DataBindXY(arrdate, arrvalue);
        webchart.Series["bb"].Points.DataBindXY(arrdate, arrvalues);
        //主要是这句来显示第二个坐标轴
        webchart.Series["bb"].YAxisType = AxisType.Secondary;
        webchart.Series["aa"].Type = SeriesChartType.Column;
        webchart.Series["bb"].Type = SeriesChartType.Line;
        string ImageName = DateTime.Now.ToString("yyMMddHHmmssfffff") + ".png";

        webchart.Save(HttpContext.Current.Request.PhysicalApplicationPath + ImageName, ChartImageFormat.Png);
        return ImageName;
    }

原创粉丝点击