epezent / implot

Immediate Mode Plotting
MIT License
4.64k stars 516 forks source link

ImGui::PlotLine doesn't rebuild itself. #456

Open SixArne opened 1 year ago

SixArne commented 1 year ago

Hi, for a school project we have to graph some data with imgui so I decided to use Implot.

ImGui::Begin("Exercise 1");
    if (ImGui::Button("Run benchmark", ImVec2(100, 20)))
    {
        BenchMarkExercise1();
    }

    if (ImPlot::BeginPlot("Exercise 1"))
    {

        ImPlot::SetupAxes("Allocation size", "Time");
        ImPlot::PlotLine("Speed", m_Iterations.data(), m_Ex1Results.data(), (int)m_Iterations.size());
        ImPlot::EndPlot();
    }

    ImGui::End();

m_Iterations is a vector of datatype double and so is m_Ex1Results. Both are initialized to hold the same size of data (10 points)

However when pressing the run benchmark button the graph doesn't display any of this new data.

SixArne commented 1 year ago
ImGui::Begin("Exercise 1");
if (ImGui::Button("Run benchmark", ImVec2(100, 20)))
{
BenchMarkExercise1();
// default value is set to "default"
m_name = "hello";
}

if (ImPlot::BeginPlot(m_name.c_str()))
{
ImPlot::PlotLine("Speed", m_Iterations.data(), m_Ex1Results.data(), (int)m_Iterations.size());
// this will now update
ImPlot::EndPlot();
}

So when I change the plot title as well it updates fine, but when I don't update the name it won't update anymore.

ImGui::Begin("Exercise 1");
if (ImGui::Button("Run benchmark", ImVec2(100, 20)))
{
BenchMarkExercise1();
//m_name = "hello";
}

if (ImPlot::BeginPlot(m_name.c_str()))
{
ImPlot::PlotLine("Speed", m_Iterations.data(), m_Ex1Results.data(), (int)m_Iterations.size());
// this won't update anymore
ImPlot::EndPlot();
}