Skip to content

bar plot visibility when using horizontal DateTime units #944

@Moo1211

Description

@Moo1211

My sample code to generate horizontal stacked bar chart with datetime to be display as x-axis. However, when I was try to set x-axis limit to the range of minDateTime.AddSeconds(-1).ToOADate() till maxDateTime.ToOADate(), the bar chart does not displayed out. I had to zoom out to certain scale only the chart appear.

P/S: minDateTime is the minimum datetime of datasets in the chart, whereas maxDateTime is the maximum datetime of datasets in the chart.

Random r = new Random();
mcChartObj.Insert(0, new MCChartObject()
{
    xs = new double[] { 1 },
    ys = new double[] { DateTime.Now.AddMinutes(count).ToOADate() },
    color = !machineRunning 
        && !machineError ? System.Drawing.Color.Yellow : machineRunning 
        && !machineError ? System.Drawing.Color.GreenYellow : System.Drawing.Color.Red,
});

mcChart.plt.Clear(p => p is PlottableBar);

foreach (MCChartObject model in mcChartObj)
{
    mcChart.plt.PlotBar(model.xs, model.ys, fillColor: model.color, horizontal: true, barWidth:0.1);
}

var min = mcChartObj.Min(x => x.ys[0]);
DateTime minDateTime = DateTime.FromOADate(min);

var max = mcChartObj.Max(x => x.ys[0]);
DateTime maxDateTime = DateTime.FromOADate(max);
mcChart.plt.Axis(minDateTime.AddSeconds(-1).ToOADate(), maxDateTime.ToOADate());
mcChart.plt.Ticks(dateTimeX: true);

Application.Current.Dispatcher.Invoke(() => { mcChart.Render(true); });
count++;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions