Manel Hkiri
Manel Hkiri

Reputation: 115

Livechart: How to show every X value

I'm using "Basic Stacked columns" to show the state and the number of tasks in every phase of the project.

I want to show x value for each column and in the annotation I want to show"Phase value" (for exemple Phase 4)

enter image description here

this is my code:

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 + ""
        });

    }

Upvotes: 0

Views: 1344

Answers (1)

Sharku
Sharku

Reputation: 1092

Just set the Seperator of your X-Axis to 1. Can be done very easily in the xaml part:

<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 is my LiveChart NameSpace.

Upvotes: 1

Related Questions