Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to create a graph, where the labels for the tikz mark are not supposed to be numbers but strings, is there a(n easy) way to achieve this with tikz-datavisualisation?

Mockup of what I am going for: enter image description here

Notice that the tikz are labeled with names. A further issue I don"t know how to fix is how to set marks ONLY where I supply data.

Exampledata I supply:

alpha 2 3
hotel 3 6
uniform 1 7

What I have so far:

\documentclass{article}
\usepackage{tikz}
\usepackage[margin=0cm,nohead]{geometry}
\usepackage[active,tightpage]{preview}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}                     %input encoding
\usetikzlibrary{datavisualization}  
\PreviewEnvironment{tikzpicture}
\begin{document}
\begin{tikzpicture}
\pgfdeclaredataformat{cacheConfigs}%
{}{}{#1 #2 #3}
{%
    \pgfkeys{/data point/.cd, x=#1, y=#2, set=1} \pgfdatapoint
    \pgfkeys{/data point/.cd, x=#1, y=#3, set=2} \pgfdatapoint
}{}{}

\datavisualization [scientific axes=clean, %y axis=grid,
style sheet=vary dashing,
visualize as line/.list={1,2}]
data[format=cacheConfigs] {
1 2 3
2 3 6
3 1 7
};
\end{tikzpicture}
\end{document}
share|improve this question
2  
Could you edit your question to provide a minimal example document that shows how you want to provide the data? –  Jake Jun 20 '13 at 23:34
    
@Jake: I hope the picture/mwe helps if there is anything else to make the question clearer let me know –  ted Jun 21 '13 at 9:45
add comment

1 Answer

up vote 1 down vote accepted

Alright, here's one way to do this: We can store the labels in a list macro and assign the data points an x value based on a simple counter. For printing the labels, we then pick out the corresponding list entry for a given x position. To have only tick marks where we also have data, you can set x axis={ticks={step=1}}

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{datavisualization}  
\begin{document}
\begin{tikzpicture}

\makeatletter
\def\ticksfromlabellist#1{%
    \pgfmathparse{{\label@list}[#1]}%
    \pgfmathresult%
}

\pgfdeclaredataformat{cacheConfigs}%
{} % No catcode changes
{\@tempcnta=1 \xdef\label@list{}} % Initialise count and label list
{#1 #2 #3}  % Argument format
{%
    \xdef\label@list{\label@list,"#1"}  % Append label to list
    \pgfkeys{/data point/.cd, x=\the\@tempcnta, y=#2, set=1} \pgfdatapoint  % Store data point, with count as x
    \pgfkeys{/data point/.cd, x=\the\@tempcnta, y=#3, set=2} \pgfdatapoint
    \advance\@tempcnta 1\relax  % Step the count
}{}{}
\makeatother

\datavisualization [
    scientific axes=clean,
    style sheet=vary dashing,
    visualize as line/.list={1,2},
    x axis={
        ticks={
            step=1,
            tick typesetter/.code=\ticksfromlabellist{##1},
            style={text height=1ex} % For proper vertical alignment
        }
    }
] data [format=cacheConfigs] {
a 2 3
b 3 6
c 1 7
};

\end{tikzpicture}
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.