Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [SVG] jak umieścić tekst na wierzchu
TomASS
post
Post #1





Grupa: Zarejestrowani
Postów: 1 660
Pomógł: 13
Dołączył: 9.06.2004
Skąd: Wrocław i okolice

Ostrzeżenie: (0%)
-----


Witajcie,

mam taki kod generujacy wykres kołowy:
Kod
var width = 200,
    height = 200,
    radius = Math.min(width, height) / 2;

var color = d3.scale.ordinal()
    .range(["#3075CA", "#406A9D", "#ABBBD9"]);


var arc = d3.svg.arc()
    .outerRadius(radius - 10)
    .innerRadius(0);

var pie = d3.layout.pie()
    .sort(null)
    .value(function(d) { return d.ilosc; });

var svg = d3.select("#chart").append("svg")
    .attr("width", width)
    .attr("height", height)
    .append("g")
    .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");

d3.csv("data.php", function(error, data) {
var total = d3.sum(data, function(d){return d.ilosc;});
    
  data.forEach(function(d) {
    d.ilosc = +d.ilosc;
  });

  var g = svg.selectAll(".arc")
      .data(pie(data))
      .enter().append("g")
      .attr("render-order", "-1")
      .attr("class", "arc");

  g.append("path")
      .attr("d", arc)
      .style("fill", function(d) { return color(d.data.narzedzie); });

  g.append("text")
      .attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; })
      .attr("dy", ".35em")
      .style("text-anchor", "middle")
      .attr("render-order", "1")
      .text(function(d) { return d.data.ilosc + "; " + d3.round(100* d.data.ilosc / total, 0) + "%"; });

});


Niestety pomimo użycia "render-order" nie wyświetla mi tekstu na wierzchu, co daje mi taki efekt (jedna liczba jest zupełnie nieczytelna):
(IMG:http://i62.tinypic.com/28r2uqg.png)

Proszę o pomoc w wyświetleniu tekstu na wierzchu
Go to the top of the page
+Quote Post
trueblue
post
Post #2





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Czy węzeł tekstowy razem z wycinkiem tworzą odrębną grupę?
Wydaje mi się, że problemem jest to, że ustawiasz render-order, ale to działa w obrębie tych dwóch elementów, a nie wobec całego kontenera SVG (wycinek 809 przykrywa ten mniejszy).
Gdyby elementy tekstowe były odrębnymi węzłami, wtedy możesz decydować o położeniu poprzez render-order.
Go to the top of the page
+Quote Post
TomASS
post
Post #3





Grupa: Zarejestrowani
Postów: 1 660
Pomógł: 13
Dołączył: 9.06.2004
Skąd: Wrocław i okolice

Ostrzeżenie: (0%)
-----


Dzięki - to może być to, ale jak to ustawić? :/
Go to the top of the page
+Quote Post
trueblue
post
Post #4





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Uniwersalny algorytm układania tego byłby kłopotliwy.
Ale może warto generować "wąskie" wycinki na samym końcu?
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 06:33