Livechart:如何显示每个X值

问题描述 投票:0回答:1

我正在使用“基本堆叠的列”来显示项目每个阶段的状态和任务数。

我想显示每列的x值,并且在批注中我想显示“阶段”(例如阶段4)

enter image description here

这是我的代码:

String[] Statuts = { "A faire", "En cours", "interrompue", "Terminée", "Annulée" };

        int j = 0;
        string[] numPhases;
        foreach (string st in Statuts)
        {
            double[] valeurSerie = new double[5];
            string sql_Statut = "SELECT distinct Phases.RefPhase ,COALESCE(nb, 0)  AS nb  " +
              " FROM Phases LEFT JOIN " +
              " (SELECT RefPhase, count(*) AS nb " +
              " from Taches  where IDprojet = '" + idprojet + "'  and statut = '" + st + "' group by RefPhase) Taches " +
              " On Phases.RefPhase = Taches.RefPhase";//find for each phase the number of the state of tasks

            SqlCommand cmd3 = new SqlCommand(sql_Statut, connexion.OpenConnexion());
            DataTable dt3 = new DataTable();
            dt3.Load(cmd3.ExecuteReader());
            connexion.CloseConnexion();
            numPhases=new string[dt3.Rows.Count];
            int i = 0;
            foreach (DataRow dr in dt3.Rows)
            {

                valeurSerie[i] = (double)(int)dr["nb"];

                cartesianChart1.Series[j].Values.Add(valeurSerie[i]); 


                if (j == 0)
                {

                    numPhases[i] = dr["RefPhase"].ToString();//number of each phase
                }
                      i++;
            }
            if (j == 0)
            {
                cartesianChart1.AxisX.Add(new LiveCharts.Wpf.Axis //phases
                {
                    Title = "Phases",
                    Labels = numPhases,
                    LabelFormatter = value => "Phase " + value,//****this is NOT SHOWN Why?*****
                    ShowLabels = true,//**** this dont't work why?****
                    Separator = DefaultAxes.CleanSeparator
                });
            }
                j++;

        }


        cartesianChart1.AxisY.Add(new LiveCharts.Wpf.Axis 
        {
            Title = "Taches",
            LabelFormatter = value => value + ""
        });

    }
c# livecharts
1个回答
0
投票

只需将X轴的分隔符设置为1。可以在xaml部分中很容易地完成:

<lc:CartesianChart x:Name="Chart" Series="{Binding SeriesCollection}" >
    <lc:CartesianChart.AxisX>
        <lc:Axis Title="{Binding XTitle}" Labels="{Binding XLabels}" LabelsRotation="-45" FontSize="15">
            <lc:Axis.Separator>
                <lc:Separator Step="1"/>
            </lc:Axis.Separator>
        </lc:Axis>
    </lc:CartesianChart.AxisX>
</lc:CartesionChart>

lc是我的LiveChart命名空间。

© www.soinside.com 2019 - 2024. All rights reserved.