我正在使用“基本堆叠列”来显示项目每个阶段的状态和任务数。
我想显示每列的x值,并在注释中显示“阶段值”(例如阶段4)
这是我的代码:
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 + ""
});
}
答案 0 :(得分:1)
只需将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命名空间。