如何创建时间线图表控件的东西? [英] How to create a timeline chart control thing?

查看:126
本文介绍了如何创建时间线图表控件的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建时间轴,并且一直在尝试使用图表控件。但是它不起作用,因为我只需要X值,而图表系列就像,只有AddY或AddXY,就没有AddX / AddXX2。

I am trying to create a timeline, and have been trying to use chart control. but it is not working out as i only need the X value and the chart series is like, only AddY or AddXY, there's no AddX/AddXX2.

我知道,之前的问题之类的东西。有人问过

I know there's like, questions like this before and stuff. There's this person that asked


如何创建时间轴控件?

How to create a timeline control?

就像3年前一样,但我不确定他们在回答和评论中到底在说什么。

like, 3 years ago but i'm not sure what exactly they are saying in the answers and comments..

我当前的代码是:

 DirectoryInfo dInfo = new DirectoryInfo(tbSelectFolder.Text);
        FileInfo[] Files = dInfo.GetFiles("*.ts");
        List<string> fileNames = new List<string>();

        List<DateTime> fileDates = new List<DateTime>();


        chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.White;
        chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.White;
        chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Solid;
        chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
        chart1.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.White;
        chart1.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.White;
        chart1.ChartAreas[0].AxisX2.Enabled = AxisEnabled.True;

        foreach (FileInfo file in Files)
        {
            string filename = Path.GetFileNameWithoutExtension(file.Name);
            string[] fileNameSplit = filename.Split(' ');
            fileNames.Add(fileNameSplit[0]);

            DateTime date = DateTime.ParseExact(fileNameSplit[1], "yyMMdd",null);
            fileDates.Add(date);
        }


        foreach (var value in fileNames)
        {
            foreach (var value1 in fileDates)
            {
                chart1.Series["US"].Points.AddXY(value1, value); 
            }
        }

这基本上是给我的

我要创建的时间表基本上就像一个时间表。因此,有没有办法使它看起来像这样

The timeline i'm trying to create is basically like a time table. So, is there a way to make it look something like this

推荐答案

我希望这符合您的需求:不幸的是,axis-label aren不太完美,这就是为什么您可以通过取消注释前三行代码来完全删除它们的原因。

I hope this fits your needs: unfortunately the axis-label aren't perfect, thats why you can remove them completely by uncommenting the first three line of code .

//Just pass your list of dates to this function
private void DrawTimeline(List<DateTime> dates)
{

    //chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Black;
    //chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.White;
    //chart1.ChartAreas[0].AxisX.LabelStyle.Enabled = false;
    chart1.ChartAreas[0].AxisY.IsStartedFromZero = false;

    //initialize a legend with some settings
    chart1.Legends.Clear();
    chart1.Legends.Add("Timespans");
    chart1.Legends[0].LegendStyle = LegendStyle.Table;
    chart1.Legends[0].Docking = Docking.Bottom;
    chart1.Legends[0].Alignment = StringAlignment.Center;
    chart1.Legends[0].Title = "Timespans";
    chart1.Legends[0].BorderColor = Color.Black;

    chart1.Series.Clear();
    string seriesname;
    //adding the bars with some settings
    for (int i = 0; i < dates.Count-1; i++)
    {
        seriesname = Convert.ToString(dates[i].Date + " - " + dates[i + 1].Date);
        chart1.Series.Add(seriesname);
        chart1.Series[seriesname].ChartType = SeriesChartType.RangeBar;
        chart1.Series[seriesname].YValuesPerPoint = 2;
        chart1.Series[seriesname].Points.AddXY("Timeline", dates[i].Date, dates[i + 1].Date);
        chart1.Series[seriesname]["DrawSideBySide"] = "false";
        chart1.Series[seriesname].BorderColor = Color.Black;
        chart1.Series[seriesname].ToolTip = seriesname;
    }
}

这篇关于如何创建时间线图表控件的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆