[vtkusers] vtkChartXY - need help

Marcus D. Hanwell marcus.hanwell at kitware.com
Wed Jun 29 11:41:06 EDT 2011


On Tue, Jun 28, 2011 at 3:16 PM, Amitesh Kumar <amiteshagarwal at gmail.com>wrote:

> Thank you very much for your reply!  My apology for writing late but it is
> only today that I finally gotten around to test my code. I have one final
> question regarding vtk charts. If my x-axis labels are string or char* then
> how can I display them? In my case my x-axis labels are in the form of
> "x1-x2". I first tried using  xLegends (in my code) as vtkStringArray with
> actual xAxis labels in there but that didn't work as my guess was that
> vtkCharts API tried to sort the points in the table. When that didn't work I
> tried using xLegends as vtkIntArray with indices 0 to n-1 for n bars in the
> bar plot which correctly created the plot. However 0 to n-1 is clearly not
> the right label in my case and I want use the values stored in xLabels
> (vtkStringArray) for my x-axis labels. I tried using setindexedLabels method
> as shown below but that absolutely didn't seem to have any effect on the
> x-axis labels which were all int.
>
> void vtkPlot::SetIndexedLabels(vtkStringArray<http://www.vtk.org/doc/nightly/html/classvtkStringArray.html>
>  * *labels*)
>
> My plotting part of the code is as following. Note I am using vtk nightly
> 5.9 for this. Do you have any idea how to solve this problem.
>
> The function you outline above is for setting tooltip text for points in a
plot, so if you plotted a table,

 x  |  y  | labels
 0  |  0  | zero
 1  |  3  | three
 2  |  9  | nine

If you set x and y as normal for the plot, and used a vtkStringArray as that
third column (labels) then the tooltip text when your mouse is over the
point would be the "zero", "three" and "nine" for example.

What I think you want is custom labels on vtkAxis. So you would want to
fetch the axis you are interested in, and set the custom text there. For a
full example of custom labels on points in plots see the scatter plot test,

http://vtk.org/gitweb?p=VTK.git;a=blob;f=Charts/Testing/Cxx/TestScatterPlot.cxx

For an example of setting custom axis labels from strings see test stacked
bar graph,

http://vtk.org/gitweb?p=VTK.git;a=blob;f=Charts/Testing/Cxx/TestStackedBarGraph.cxx

Specifically using a vtkDoubleArray and a vtkStringArray for the locations
and strings at those locations,

axis->SetTickPositions(dates);
axis->SetTickLabels(strings);

Hope that helps, the tests should be a good source of up to date, well
tested examples.

Marcus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110629/d46be54c/attachment.htm>


More information about the vtkusers mailing list