[vtk-developers] Straight line in a chartXY

Marcus D. Hanwell marcus.hanwell at kitware.com
Sat Jan 15 21:41:51 EST 2011


Hi,

On Sat, Jan 15, 2011 at 6:59 PM, Martin Waitzbauer <mazzok at gmx.at> wrote:
> Hello, There!
>
> I'm currently about to create some graphics in a chartXY
> i was looking through teh examples, but i couldn find something according to my needs
>
> I added several line plots, displaying functiosn to the chart, now i wanna have a straight line, so lets say going from Point P1(5,0) to P2(5,1)
>
> unfortunatly a Line plot will not create such an one point peak

Why do you say that? I just created a new test that has a table with
two points - the line is drawn between the points. I will be adding a
new test that ensures unusual charts with a small number of points are
rendered as expected. If this doesn't work could you try it with the
latest VTK (git master branch)?
>
> bar plots seem to be invariant in width change (dont respond to setSize)
>
> do you know of anything that could help me?

I think that you should be able to use the line plot, and I will add a
test shortly to demonstrate/test this edge case. Seems to work fine
locally, but it would be good to get dashboard coverage with different
machines. The crux of the code in the new test is pasted below, and
should produce two tables, one with 2 points and another with 4
points.

Marcus

  // Create a table with two points in it...
  vtkSmartPointer<vtkTable> table1 = vtkSmartPointer<vtkTable>::New();
  vtkSmartPointer<vtkFloatArray> X1 = vtkSmartPointer<vtkFloatArray>::New();
  X1->SetName("X1");
  table1->AddColumn(X1);
  vtkSmartPointer<vtkFloatArray> Y1 = vtkSmartPointer<vtkFloatArray>::New();
  Y1->SetName("Y1");
  table1->AddColumn(Y1);
  // Another table with 4 points in it
  vtkSmartPointer<vtkTable> table2 = vtkSmartPointer<vtkTable>::New();
  vtkSmartPointer<vtkFloatArray> X2 = vtkSmartPointer<vtkFloatArray>::New();
  X2->SetName("X2");
  table2->AddColumn(X2);
  vtkSmartPointer<vtkFloatArray> Y2 = vtkSmartPointer<vtkFloatArray>::New();
  Y2->SetName("Y2");
  table2->AddColumn(Y2);
  // Test charting with a few points...
  table1->SetNumberOfRows(2);
  table1->SetValue(0, 0, 0.0);
  table1->SetValue(0, 1, 0.3);
  table1->SetValue(1, 0, 5.0);
  table1->SetValue(1, 1, 0.6);
  table2->SetNumberOfRows(4);
  table2->SetValue(0, 0, 0.0);
  table2->SetValue(0, 1, 0.0);
  table2->SetValue(1, 0, 0.0);
  table2->SetValue(1, 1, 0.4);
  table2->SetValue(2, 0, 1.7);
  table2->SetValue(2, 1, 0.7);
  table2->SetValue(3, 0, 5.0);
  table2->SetValue(3, 1, 0.4);

  // Add multiple line plots, setting the colors etc
  vtkPlot *line = chart->AddPlot(vtkChart::LINE);
  line->SetInput(table1, 0, 1);
  line->SetColor(0, 255, 0, 255);
  line->SetWidth(1.0);
  line = chart->AddPlot(vtkChart::LINE);
  line->SetInput(table2, 0, 1);
  line->SetColor(255, 0, 0, 255);
  line->SetWidth(1.0);



More information about the vtk-developers mailing list