垂直线这个能用go.Line函数写吗
时间: 2024-02-11 14:05:33 浏览: 127
可以使用go.Line函数来绘制垂直线。示例如下:
```go
import (
"github.com/go-echarts/go-echarts/v2/components"
"github.com/go-echarts/go-echarts/v2/types"
)
func drawVerticalLine() {
line := []interface{}{
[]int{1, 2},
[]int{3, 4},
[]int{5, 6},
}
xData := []string{"A", "B", "C"}
yData := []string{"1", "2", "3", "4", "5", "6"}
graph := components.NewLine().
SetGlobalOptions(
components.WithInitializationOpts(opts.Initialization{
Width: "100%",
Height: "500px",
Theme: "dark",
}),
components.WithTitleOpts(opts.Title{
Title: "Vertical Line",
Subtitle: "This is a vertical line chart",
}),
components.WithLegendOpts(opts.Legend{Show: true}),
components.WithTooltipOpts(opts.Tooltip{Show: true}),
components.WithYAxisOpts(opts.YAxis{
Type: "category",
Data: yData,
}),
components.WithXAxisOpts(opts.XAxis{
Type: "category",
Data: xData,
}),
).
AddSeries("Category A", line, types.ChartLineOpts{Smooth: true})
f, err := os.Create("vertical_line.html")
if err != nil {
panic(err)
}
graph.Render(f)
}
```
在上面的示例中,我们使用go-echarts库来绘制一个垂直线图。其中,我们使用了go.Line函数来定义线的坐标,将其传递给了AddSeries函数来添加到图表中。在设置x轴的类型为category时,可以用xData来指定x轴的标签。
阅读全文